perm filename LSPDC1.XGP[206,LSP] blob sn#307215 filedate 1977-09-27 generic text, type T, neo UTF8
/LMAR=0/XLINE=3/FONT#0=BAXL30/FONT#1=BAXM30/FONT#2=BAXB30/FONT#3=SUB/FONT#4=SUP/FONT#5=NGR25/FONT#6=NGR20/FONT#7=MATH30/FONT#9=GRK30/FONT#10=MS25/FONT#11=GRFX25/FONT#12=GRFX35



␈↓ ↓H␈↓α␈↓ ∧/RECURSIVE PROGRAMMING IN LISP





␈↓ ↓H␈↓α␈↓ ¬Jby John McCarthy





















␈↓ ↓H␈↓α␈↓ ¬AStanford University






␈↓ ↓H␈↓α␈↓ ∧OCopyright ␈↓
c␈↓α 1977 by John McCarthy










␈↓ ↓H␈↓␈↓ βpThis version printed at 22:47 on September 19, 1977.
␈↓ ↓H␈↓␈↓ εH␈↓ ?i


␈↓ ↓H␈↓α␈↓ ¬NTable of Contents



␈↓ ↓H␈↓␈↓ 	Page



␈↓ ↓H␈↓I␈↓ α_INTRODUCTION TO LISP

␈↓ ↓H␈↓␈↓ α81␈↓ αxLists.␈↓ βx␈↓ ∧8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓ ≠   1

␈↓ ↓H␈↓␈↓ α82␈↓ αxAtoms.␈↓ βx␈↓ ∧8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓ ≠   3

␈↓ ↓H␈↓␈↓ α83␈↓ αxList structures.␈↓ ∧8␈↓ ∧x   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓ ≠   3

␈↓ ↓H␈↓␈↓ α84␈↓ αxS-expressions.␈↓ ∧8␈↓ ∧x   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓ ≠   4

␈↓ ↓H␈↓␈↓ α85␈↓ αxThe basic functions and predicates of LISP.␈↓ π8␈↓ πx   .   .   .   .   .   .   .   .   .   .   .␈↓ ≠   7

␈↓ ↓H␈↓␈↓ α86␈↓ αxConditional expressions.␈↓ ¬8␈↓ ¬x   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓ ≠   9

␈↓ ↓H␈↓␈↓ α87␈↓ αxBoolean expressions.␈↓ ∧x␈↓ ¬8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    11

␈↓ ↓H␈↓␈↓ α88␈↓ αxRecursive function definitions.␈↓ ¬x␈↓ ε8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    12

␈↓ ↓H␈↓␈↓ α89␈↓ αxLambda expressions and functions with functions as arguments.␈↓ 	8␈↓ 	x   .   .   .   .␈↓    18

␈↓ ↓H␈↓␈↓ α810␈↓ αxLabel.␈↓ βx␈↓ ∧8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    21

␈↓ ↓H␈↓␈↓ α811␈↓ αxNumerical computation.␈↓ ¬8␈↓ ¬x   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    22


␈↓ ↓H␈↓II␈↓ α_HOW TO WRITE RECURSIVE FUNCTION DEFINITIONS

␈↓ ↓H␈↓␈↓ α81␈↓ αxStatic and dynamic ways of programming.␈↓ π8␈↓ πx   .   .   .   .   .   .   .   .   .   .   .␈↓    24

␈↓ ↓H␈↓␈↓ α82␈↓ αxSimple list recursion.␈↓ ∧x␈↓ ¬8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    25

␈↓ ↓H␈↓␈↓ α83␈↓ αxSimple S-expression recursion.␈↓ ¬x␈↓ ε8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    27

␈↓ ↓H␈↓␈↓ α84␈↓ αxOther structural recursions.␈↓ ¬x␈↓ ε8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    28

␈↓ ↓H␈↓␈↓ α85␈↓ αxTree search recursion.␈↓ ¬8␈↓ ¬x   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    29

␈↓ ↓H␈↓␈↓ α86␈↓ αxGame trees.␈↓ ∧8␈↓ ∧x   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    33
␈↓ ↓H␈↓ii␈↓ ¬RTable of Contents␈↓ H


␈↓ ↓H␈↓III␈↓ α_PROVING LISP PROGRAMS CORRECT

␈↓ ↓H␈↓␈↓ α81␈↓ αxIntroductory Example.␈↓ ¬8␈↓ ¬x   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    37

␈↓ ↓H␈↓␈↓ α82␈↓ αxFirst Order Logic with Conditional Forms and Lambda-expressions.␈↓ 	x␈↓ 
8   .   .␈↓    39

␈↓ ↓H␈↓␈↓ α83␈↓ αxConditional Forms.␈↓ ∧x␈↓ ¬8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    41

␈↓ ↓H␈↓␈↓ α84␈↓ αxLambda-expressions.␈↓ ¬8␈↓ ¬x   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    43

␈↓ ↓H␈↓␈↓ α85␈↓ αxFirst Order Axioms for LISP.␈↓ ¬x␈↓ ε8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    44

␈↓ ↓H␈↓␈↓ α86␈↓ αxAxiom Schemas of Induction.␈↓ ¬x␈↓ ε8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    45

␈↓ ↓H␈↓␈↓ α87␈↓ αxA Simple Example.␈↓ ∧x␈↓ ¬8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    46

␈↓ ↓H␈↓␈↓ α88␈↓ αxFunctionals and Least Fixedpoints.␈↓ ε8␈↓ εx   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    49

␈↓ ↓H␈↓␈↓ α89␈↓ αxPseudo-logic.␈↓ ∧8␈↓ ∧x   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    52

␈↓ ↓H␈↓␈↓ α810␈↓ αxAn Extended Example.␈↓ ¬8␈↓ ¬x   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    56

␈↓ ↓H␈↓␈↓ α811␈↓ αxThe Minimization Schema.␈↓ ¬x␈↓ ε8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    62


␈↓ ↓H␈↓IV␈↓ α_INTERPRETING AND COMPILING IN LISP

␈↓ ↓H␈↓␈↓ α81␈↓ αxThe function ␈↓↓eval.␈↓␈↓ ∧x␈↓ ¬8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    68

␈↓ ↓H␈↓␈↓ α82␈↓ αxIntroduction to Compiling LISP.␈↓ ε8␈↓ εx   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    70

␈↓ ↓H␈↓␈↓ α83␈↓ αxSome facts about the PDP-10.␈↓ ¬x␈↓ ε8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    71

␈↓ ↓H␈↓␈↓ α84␈↓ αxCode produced by LISP compilers.␈↓ ε8␈↓ εx   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    72

␈↓ ↓H␈↓␈↓ α85␈↓ αxLCOM0.␈↓ βx␈↓ ∧8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    77

␈↓ ↓H␈↓␈↓ α86␈↓ αxLCOM4.␈↓ βx␈↓ ∧8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    81


␈↓ ↓H␈↓V␈↓ α_COMPUTABILITY

␈↓ ↓H␈↓␈↓ α81␈↓ αxA universal LISP function.␈↓ ¬x␈↓ ε8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    88

␈↓ ↓H␈↓␈↓ α82␈↓ αxNon-computability.␈↓ ∧x␈↓ ¬8   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .␈↓    89


␈↓ ↓H␈↓BIBLIOGRAPHY
␈↓ ↓H␈↓␈↓ ¬RTable of Contents␈↓ -iii


␈↓ ↓H␈↓APPENDIX I

␈↓ ↓H␈↓␈↓ α8A MICRO-MANUAL FOR LISP - MOSTLY TRUTHFUL


␈↓ ↓H␈↓APPENDIX II

␈↓ ↓H␈↓␈↓ α8Examples of Computer-checked Proofs


␈↓ ↓H␈↓APPENDIX III

␈↓ ↓H␈↓␈↓ α8MACLISP listing of LCOM0.


␈↓ ↓H␈↓APPENDIX IV

␈↓ ↓H␈↓␈↓ α8MACLISP listing of LCOM4.
␈↓ ↓H␈↓␈↓ εH␈↓ 91


␈↓ ↓H␈↓α␈↓ επChapter I

␈↓ ↓H␈↓α␈↓ ¬εINTRODUCTION TO LISP




␈↓ ↓H␈↓1.  ␈↓αLists.␈↓


␈↓ ↓H␈↓        Symbolic␈αinformation␈αin␈αLISP␈αis␈α expressed␈α by␈α S-expressions␈αand␈α these␈α are␈α represented
␈↓ ↓H␈↓in␈α∞ the␈α
 memory␈α∞of␈α
the␈α∞computer␈α∞by␈α
list␈α∞structures.␈α
Before␈α∞giving␈α
formal␈α∞ definitions,␈α∞ we␈α
 shall
␈↓ ↓H␈↓give  some examples.

␈↓ ↓H␈↓        The most common form of S-expression is the  list,  and  here are some lists:

␈↓ ↓H␈↓The list
␈↓ ↓H␈↓        ␈↓¬(A B C E)␈↓
␈↓ ↓H␈↓has four elements.

␈↓ ↓H␈↓The list
␈↓ ↓H␈↓        ␈↓¬(A B (C D) E)␈↓
␈↓ ↓H␈↓has four elements one of which is itself a list.

␈↓ ↓H␈↓The list
␈↓ ↓H␈↓        ␈↓¬(A)␈↓
␈↓ ↓H␈↓has one element.

␈↓ ↓H␈↓The list
␈↓ ↓H␈↓        ␈↓¬((A B C D))␈↓
␈↓ ↓H␈↓also has one element which itself is a list.

␈↓ ↓H␈↓The list
␈↓ ↓H␈↓        ␈↓¬()␈↓
␈↓ ↓H␈↓has no elements; it is also written
␈↓ ↓H␈↓        ␈↓¬NIL␈↓.

␈↓ ↓H␈↓The list
␈↓ ↓H␈↓        ␈↓¬(PLUS X Y)␈↓
␈↓ ↓H␈↓has three elements and may be used to represent the expression
␈↓ ↓H␈↓        ␈↓↓x + y␈↓.

␈↓ ↓H␈↓The list
␈↓ ↓H␈↓        ␈↓¬(PLUS (TIMES X Y) X 3)␈↓
␈↓ ↓H␈↓has four elements and may be used to represent the expression
␈↓ ↓H␈↓        ␈↓↓xy + x + 3␈↓.

␈↓ ↓H␈↓The list
␈↓ ↓H␈↓2␈↓ ¬oCHAPTER I␈↓ H


␈↓ ↓H␈↓        ␈↓¬(EXIST X (ALL Y (IMPLIES (P X) (P Y))))␈↓
␈↓ ↓H␈↓may be used to represent the logical expression
␈↓ ↓H␈↓        ␈↓↓(∃x)(∀y).P(x)⊃P(y)␈↓.

␈↓ ↓H␈↓The list
␈↓ ↓H␈↓        ␈↓¬(INTEGRAL 0 ∞ (TIMES (EXP (TIMES I X Y)) (F X)) X)␈↓
␈↓ ↓H␈↓may be used to represent the expression
␈↓ ↓H␈↓        ␈↓πI␈↓β0␈↓∧␈↓#
∞␈↓#␈↓↓e␈↓∧ixy␈↓↓f(x)dx␈↓.

␈↓ ↓H␈↓The list
␈↓ ↓H␈↓        ␈↓¬((A B) (B A C D) (C B D E) (D B C E) (E C D F) (F E))␈↓

␈↓ ↓H␈↓is␈αused␈αto␈α
represent␈αthe␈αnetwork␈αof␈α
figure 1␈αaccording␈α to␈α a␈α
 scheme␈αwhereby␈α there␈α is␈α
a␈αsublist
␈↓ ↓H␈↓for each vertex consisting of the vertex itself followed by the vertices to which it is connected.




␈↓"␈↓ ↓H␈↓␈↓ ε8C
␈↓"␈↓ ↓H␈↓␈↓ ε_≤'~`≥
␈↓"␈↓ ↓H␈↓␈↓ ¬x≤'  ~  `≥
␈↓"␈↓ ↓H␈↓␈↓ ¬8B ≤'    ~    `≥ E
␈↓"␈↓ ↓H␈↓␈↓ ∧(A αααααααα␈↓ ¬H'␈↓ ¬H≥␈↓ ε8~␈↓ π(≤␈↓ π(`αααααααα F
␈↓"␈↓ ↓H␈↓␈↓ ¬X`≥    ~    ≤'
␈↓"␈↓ ↓H␈↓␈↓ ¬x`≥  ~  ≤'
␈↓"␈↓ ↓H␈↓␈↓ ε_`≥~≤'
␈↓"␈↓ ↓H␈↓␈↓ ε8D



␈↓"␈↓ ↓H␈↓                                    Figure 1.


␈↓ ↓H␈↓        The␈α
 elements␈α
 of␈α
 a␈α
 list␈α
 are␈α∞surrounded␈α
by␈α
parentheses␈α
and␈α
separated␈α
by␈α
spaces.␈α∞ A␈α
list
␈↓ ↓H␈↓may␈α
have␈α
any␈α
number␈α
of␈αterms␈α
and␈α
any␈α
 of␈α
these␈α
 terms␈α may␈α
 themselves␈α
 be␈α
 lists.␈α
  In␈α this␈α
case,
␈↓ ↓H␈↓the␈αspaces␈αsurrounding␈αa␈αsublist␈α may␈α be␈α omitted,␈α and␈α extra␈α spaces␈α between␈αelements␈αof␈αa␈αlist
␈↓ ↓H␈↓are allowed.  Thus the lists

␈↓ ↓H␈↓        ␈↓¬(A B(C  D)    E)␈↓

␈↓ ↓H␈↓and

␈↓ ↓H␈↓        ␈↓¬(A B (C D) E)␈↓

␈↓ ↓H␈↓are regarded as the same.
␈↓ ↓H␈↓␈↓ ¬oCHAPTER I␈↓ 93


␈↓ ↓H␈↓2.  ␈↓αAtoms.␈↓


␈↓ ↓H␈↓        The␈αexpressions␈α␈↓¬A,␈αB,␈α
X,␈αY,␈α3,␈αPLUS␈↓,␈α
and␈α␈↓¬ALL␈↓␈αoccurring␈αin␈α
the␈αabove␈α lists␈αare␈α
called␈αatoms.
␈↓ ↓H␈↓In␈αgeneral,␈αan␈α
atom␈αis␈αexpressed␈αby␈α
a␈αsequence␈αof␈αcapital␈α
letters,␈α digits,␈α and␈α
 special␈α characters
␈↓ ↓H␈↓with␈α⊃certain␈α⊃ exclusions.␈α⊂  The␈α⊃exclusions␈α⊃are␈α⊂<space>,␈α⊃<carriage␈α⊃return>,␈α⊂and␈α⊃the␈α⊃other␈α⊂non-
␈↓ ↓H␈↓printing␈α
 characters,␈α
 and␈α
 also␈α
 the␈α
 parentheses,␈α
brackets,␈α
 semi-colon,␈α
 and␈α
 comma.␈α  Numbers
␈↓ ↓H␈↓are␈α∂expressed␈α∂as␈α∂signed␈α∂decimal␈α∂or␈α∞octal␈α∂numbers,␈α∂ the␈α∂ exact␈α∂ convention␈α∂ depending␈α∂ on␈α∞ the
␈↓ ↓H␈↓implementation.␈α_ Floating␈α→ point␈α_ numbers␈α→ are␈α_ written␈α_ with␈α→decimal␈α_points␈α→and,␈α_when
␈↓ ↓H␈↓appropriate,␈α⊃an␈α⊃exponent␈α∩notation␈α⊃depending␈α⊃ on␈α∩ the␈α⊃implementation.␈α⊃  The␈α∩ reader␈α⊃ should
␈↓ ↓H␈↓consult the programmer's manual for the LISP implementation he intends to use.

␈↓ ↓H␈↓        Some examples of atoms are

␈↓ ↓H␈↓        ␈↓¬THE-LAST-TRUMP ␈↓
␈↓ ↓H␈↓        ␈↓¬A307B ␈↓
␈↓ ↓H␈↓        ␈↓¬345 ␈↓
␈↓ ↓H␈↓        ␈↓¬3.14159, ␈↓

␈↓ ↓H␈↓and from these we can form lists like

␈↓ ↓H␈↓        ␈↓¬((345 3.14159 -47) A307B THE-LAST-TRUMP -45.21)␈↓.



␈↓ ↓H␈↓3.  ␈↓αList structures.␈↓


␈↓ ↓H␈↓        Lists␈α are␈α represented␈α
in␈αthe␈αmemory␈α
of␈αthe␈αcomputer␈α
by␈αlist␈αstructures.␈α
   A␈αlist␈αstructure␈α
is
␈↓ ↓H␈↓a␈α∂collection␈α⊂of␈α∂memory␈α⊂words␈α∂ each␈α⊂of␈α∂ which␈α∂ is␈α⊂ divided␈α∂ into␈α⊂ two␈α∂ parts,␈α⊂and␈α∂each␈α⊂part␈α∂is
␈↓ ↓H␈↓capable␈αof␈α
containing␈αan␈αaddress␈α
in␈αmemory.␈αThe␈α
two␈αparts␈α
are␈αcalled␈αare␈α
 called␈αthe␈α a-part␈α
 and
␈↓ ↓H␈↓the␈α∞ d-part.␈α∞ There␈α∂ is␈α∞ one␈α∞computer␈α∂word␈α∞for␈α∞each␈α∞element␈α∂of␈α∞the␈α∞list,␈α∂and␈α∞the␈α∞a-part␈α∂of␈α∞the
␈↓ ↓H␈↓word␈α
contains␈α
the␈α
 address␈α
of␈αthe␈α
list␈α
or␈α
atom␈α
representing␈αthe␈α
element,␈α
and␈α
the␈α
d-part␈αcontains
␈↓ ↓H␈↓the␈αaddress␈αof␈α
the␈αword␈αrepresenting␈αthe␈α
next␈αelement␈α of␈α
 the␈α list.␈α If␈αthe␈α
list␈αelement␈αis␈α
itself␈αa
␈↓ ↓H␈↓list,␈α
then,␈α
of␈α
course,␈αthe␈α
address␈α
of␈α
the␈α
first␈αword␈α
of␈α
its␈α
list␈α
structure␈αis␈α
given␈α
in␈α
the␈α
 a-part␈α of␈α
 the
␈↓ ↓H␈↓word␈α∞ representing␈α∞ that␈α∞ element.␈α∞ A␈α∞diagram␈α∞shows␈α∞this␈α∞more␈α∞clearly␈α∞than␈α∞words,␈α∞and␈α∞the␈α∞list
␈↓ ↓H␈↓structure␈α∪corresponding␈α∪to␈α∀the␈α∪ list␈α∪  ␈↓¬(PLUS␈α∀(TIMES␈α∪ X␈α∪ Y)␈α∪ X␈α∀ 3)␈↓␈α∪  which␈α∪may␈α∀represent␈α∪the
␈↓ ↓H␈↓expression  ␈↓↓xy + x + 3␈↓  is shown in figure 2.
␈↓ ↓H␈↓4␈↓ ¬oCHAPTER I␈↓ H


␈↓"
␈↓"
␈↓"␈↓ ↓H␈↓        ⊂αααπααα⊃     ⊂αααπααα⊃     ⊂αααπααα⊃     ⊂αααπααα⊃
␈↓"␈↓ ↓H␈↓  ααααα→~   ~   εαααα→~   ~   εαααα→~   ~   εαααα→~   ~   εααααααα⊃
␈↓"␈↓ ↓H␈↓        %απα∀ααα$     %απα∀ααα$     %απα∀ααα$     %απα∀ααα$       ~
␈↓"␈↓ ↓H␈↓          ↓             ~             ~             ↓             ~
␈↓"␈↓ ↓H␈↓         PLUS           ~             ~             3             ~
␈↓"␈↓ ↓H␈↓                        ~  ⊂αααπααα⊃  ~  ⊂αααπααα⊃     ⊂αααπααα⊃  ~
␈↓"␈↓ ↓H␈↓                        %α→~   ~   εααβα→~   ~   εαααα→~   ~   ~  ~
␈↓"␈↓ ↓H␈↓                           %απα∀ααα$  ~  %απα∀ααα$     %απα∀απα$  ~
␈↓"␈↓ ↓H␈↓                             ↓        ~    ~             ↓   ~    ~
␈↓"␈↓ ↓H␈↓                           TIMES      %απαα$             Y   %ααπα$
␈↓"␈↓ ↓H␈↓                                        ↓                       ↓
␈↓"␈↓ ↓H␈↓                                        X                      NIL
␈↓"
␈↓"
␈↓"␈↓ ↓H␈↓                              Figure 2.

␈↓ ↓H␈↓        Atoms␈α
 are␈α
 represented␈α
 by␈α
 the␈α
 addresses␈α
of␈α
their␈α
property␈α
lists␈α
which␈α
are␈α
list␈αstructures␈α
of
␈↓ ↓H␈↓a␈αspecial␈αkind␈α depending␈α on␈α the␈αimplementation.␈α  (In␈α some␈α implementations,␈α the␈α first␈α word
␈↓ ↓H␈↓of␈α∞a␈α∞property␈α∞list␈α∞is␈α∞in␈α∞a␈α∞special␈α∂area␈α∞of␈α∞memory,␈α∞in␈α∞others␈α∞the␈α∞first␈α∞word␈α∞is␈α∂ distinguished␈α∞ by
␈↓ ↓H␈↓sign,␈αin␈αstill␈αothers␈αit␈αhas␈αa␈αspecial␈αa-part.␈α For␈αbasic␈αLISP␈αprogramming,␈αit␈αis␈α enough␈α to␈α know
␈↓ ↓H␈↓that  atoms  are distinguishable  from  other  list  structures  by a predicate called ␈↓αat␈↓.)

␈↓ ↓H␈↓        The␈α last␈α word␈α of␈α a␈αlist␈αcannot␈αhave␈αthe␈αaddress␈αof␈αa␈αnext␈αword␈αin␈αits␈αd-part␈αsince␈αthere
␈↓ ↓H␈↓isn't any next word,  so  it  has  the address of a special atom called  ␈↓¬NIL␈↓.

␈↓ ↓H␈↓        A␈αprogram␈α
refers␈α to␈αa␈α
list␈αby␈αthe␈α
address␈αof␈α
its␈αfirst␈αelement.␈α
 According␈αto␈αthis␈α
convention,
␈↓ ↓H␈↓we␈α∞see␈α
that␈α∞the␈α
a-part␈α∞ of␈α
 a␈α∞list␈α
 word␈α∞ is␈α
 the␈α∞ list␈α
 element␈α∞ and␈α
 the␈α∞d-part␈α
is␈α∞a␈α
pointer␈α∞to␈α
a
␈↓ ↓H␈↓sublist␈α
formed␈α
by␈α
deleting␈α
the␈α
first␈α
element.␈α
 Thus␈α
the␈α
first␈α
word␈α
of␈α
the␈α
 list␈α
 structure␈α
 of␈α
 figure 2
␈↓ ↓H␈↓contains␈α a␈α pointer␈α
to␈αthe␈αlist␈α
structure␈αrepresenting␈αthe␈α
atom␈α ␈↓¬PLUS␈↓,␈αwhile␈α
its␈αd-part␈αpoints␈αto␈α
the
␈↓ ↓H␈↓list␈α
 ␈↓¬((TIMES␈α
X␈α
Y)␈αX␈α
3)␈↓.␈α
 The␈α
second␈αword␈α
contains␈α
the␈α
list␈αstructure␈α
representing␈α
 ␈↓¬(TIMES␈α
X␈α
Y)␈↓␈α in
␈↓ ↓H␈↓its␈α a-part␈α and␈α the␈α list␈α structure␈αrepresenting␈α ␈↓¬(X␈α3)␈↓␈α in␈αits␈αd-part.␈α The␈αlast␈αword␈αpoints␈αto␈αthe
␈↓ ↓H␈↓atom␈α
␈↓¬3␈↓␈α
 in␈α
its␈αa-part␈α
and␈α
has␈α
a␈α
pointer␈αto␈α
the␈α
atom␈α
 ␈↓¬NIL␈↓␈α
 in␈αits␈α
 d-part.␈α
 This␈α
is␈α
consistent␈αwith␈α
the
␈↓ ↓H␈↓convention that  ␈↓¬NIL␈↓  represents the null list.



␈↓ ↓H␈↓4.  ␈↓αS-expressions.␈↓


␈↓ ↓H␈↓        When␈α∞we␈α∞examine␈α∞the␈α∞way␈α∞list␈α∞structures␈α∞ represent␈α∞ lists␈α∞ we␈α∞see␈α∞ a␈α∂ curious␈α∞ asymmetry.
␈↓ ↓H␈↓Namely,␈α the␈α a-part␈αof␈αa␈αlist␈αword␈αcan␈αcontain␈αan␈αatom␈αor␈αa␈αlist,␈αbut␈αthe␈αd-part␈αcan␈αcontain␈αonly
␈↓ ↓H␈↓a␈αlist␈α
 or␈αthe␈α
special␈αatom␈α
 ␈↓¬NIL␈↓.␈α  This␈αrestriction␈α
is␈αquite␈α
unnatural␈αfrom␈α
the␈αcomputing␈α
point␈αof
␈↓ ↓H␈↓view,␈α∞ and␈α∞ we␈α∞ shall␈α∞ allow␈α∞ arbitrary␈α∞ atoms␈α∞ to␈α∞inhabit␈α∞ the␈α∞ d-parts␈α∞ of␈α∞ words,␈α∞but␈α∞then␈α∞we
␈↓ ↓H␈↓must␈α∩generalize␈α∩the␈α∪way␈α∩list␈α∩structures␈α∪are␈α∩expressed␈α∩as␈α∩character␈α∪strings.␈α∩To␈α∩ do␈α∪ this,␈α∩ we
␈↓ ↓H␈↓introduce the notion of S-expression.
␈↓ ↓H␈↓␈↓ ¬oCHAPTER I␈↓ 95


␈↓ ↓H␈↓        An␈α∩ S-expression␈α⊃is␈α∩either␈α⊃an␈α∩atom␈α∩or␈α⊃a␈α∩pair␈α⊃of␈α∩S-expressions␈α⊃separated␈α∩by␈α∩" . "␈α⊃and
␈↓ ↓H␈↓surrounded by parentheses.   In  BNF,  we  can write

␈↓ ↓H␈↓        <S-expression> ::= <atom> | (<S-expression> . <S-expression>).

␈↓ ↓H␈↓Examples of S-expressions are

␈↓ ↓H␈↓        ␈↓¬A ␈↓
␈↓ ↓H␈↓        ␈↓¬(A . B)␈↓
␈↓ ↓H␈↓        ␈↓¬(A . (B . A))␈↓
␈↓ ↓H␈↓        ␈↓¬(PLUS . (X . (Y . NIL)))␈↓
␈↓ ↓H␈↓        ␈↓¬(3 . 3.4)␈↓

␈↓ ↓H␈↓The␈α⊂spaces␈α⊂around␈α⊂the␈α⊂.␈α⊂may␈α⊂be␈α⊂ omitted␈α⊂ when␈α⊂ this␈α⊂ will␈α⊂ not␈α⊂ cause␈α⊂confusion.␈α⊂  The␈α⊂only
␈↓ ↓H␈↓possible␈α
confusion␈αis␈α
of␈αthe␈α
dot␈αseparator␈α
with␈α
a␈αdecimal␈α
point␈αin␈α
numbers.␈α Thus,␈α
in␈α
the␈αabove
␈↓ ↓H␈↓cases,␈α∂we␈α⊂ may␈α∂ write␈α⊂␈↓¬(A.B)␈↓,␈α∂ ␈↓¬(A.(B.A))␈↓,␈α⊂ and␈α∂ ␈↓¬(PLUS.(X.(Y.NIL)))␈↓,␈α⊂ but␈α∂if␈α⊂we␈α∂wrote␈α⊂␈↓¬(3.3.4)␈↓␈α∂confusion
␈↓ ↓H␈↓would result.

␈↓ ↓H␈↓        In␈αthe␈α
memory␈αof␈α
a␈αcomputer,␈αan␈α
S-expression␈α is␈α
 represented␈αby␈α the␈α
 address␈αof␈α
a␈αword
␈↓ ↓H␈↓whose␈αa-part␈αcontains␈αthe␈αfirst␈αelement␈αof␈αthe␈αpair␈αand␈αwhose␈αd-part␈αcontains␈αthe␈αsecond␈αelement
␈↓ ↓H␈↓of␈α
 the␈α pair.␈α
 Thus,␈α the␈α
S-expressions␈α ␈↓¬(A.B),␈α
 (A.(B.A))␈↓,␈αand␈α
 ␈↓¬(PLUS.(X.(Y.NIL)))␈↓␈αare␈α
represented␈αby
␈↓ ↓H␈↓the list structures of figure 3.
␈↓"
␈↓"
␈↓"␈↓ ↓H␈↓            ⊂αααπααα⊃                             ⊂αααπααα⊃     ⊂αααπααα⊃
␈↓"␈↓ ↓H␈↓       αααα→~   ~   ~                        αααα→~   ~   εαααα→~   ~   ~
␈↓"␈↓ ↓H␈↓            %απα∀απα$                             %απα∀ααα$     %απα∀απα$
␈↓"␈↓ ↓H␈↓              ↓   ↓                                 ~             ↓   ~
␈↓"␈↓ ↓H␈↓              A   B                                 ~             B   ~
␈↓"␈↓ ↓H␈↓                                                    ~                 ~
␈↓"␈↓ ↓H␈↓                                                    ~                 ~
␈↓"␈↓ ↓H␈↓                                                    %ααααααααπαααααααα$
␈↓"␈↓ ↓H␈↓                                                             ↓
␈↓"␈↓ ↓H␈↓                                                             A
␈↓"
␈↓"␈↓ ↓H␈↓            ⊂αααπααα⊃     ⊂αααπααα⊃     ⊂αααπααα⊃
␈↓"␈↓ ↓H␈↓       αααα→~   ~   εαααα→~   ~   εαααα→~   ~   ~
␈↓"␈↓ ↓H␈↓            %απα∀ααα$     %απα∀ααα$     %απα∀απα$
␈↓"␈↓ ↓H␈↓              ↓             ↓             ↓   ↓
␈↓"␈↓ ↓H␈↓             PLUS           X             Y  NIL
␈↓"
␈↓"
␈↓"
␈↓"␈↓ ↓H␈↓                                  Figure 3.

␈↓ ↓H␈↓        Note␈αthat␈αthe␈αlist␈α␈↓¬(PLUS␈αX␈α
Y)␈↓␈αand␈αthe␈αS-expression␈α␈↓¬(PLUS␈α.␈α
(X␈α.␈α(Y␈α.␈αNIL)))␈↓␈α are␈αrepresented␈α
 in
␈↓ ↓H␈↓memory␈α by␈α the␈α same␈α list␈α
structure.␈α The␈αsimplest␈αway␈αto␈α
treat␈αthis␈αis␈αto␈αregard␈αS-expressions␈α
as
␈↓ ↓H␈↓primary␈α
and␈α
lists␈α
 as␈α
 abbreviations␈α
 for␈α
 certain␈α
 S-expressions,␈α
namely␈α
those␈α
that␈α
never␈αhave␈α
any
␈↓ ↓H␈↓atom␈αbut␈α ␈↓¬NIL␈↓␈α as␈αthe␈αsecond␈αpart␈αof␈αa␈αpair.␈αIn␈αgiving␈α input␈α to␈α LISP,␈α either␈α the␈α list␈α form␈α or
␈↓ ↓H␈↓the␈αS-expression␈α form␈αmay␈αbe␈αused␈αfor␈αlists.␈α On␈α
output,␈αLISP␈αwill␈αprint␈αa␈αlist␈αstructure␈αas␈αa␈α
 list
␈↓ ↓H␈↓as␈α
 far␈α
 as␈α
 it␈α
 can,␈α
 otherwise␈α
 as␈α
 an␈αS-expression.␈α
 Thus,␈α
 some␈α
list␈α
structures␈α
will␈α
be␈α
printed␈αin␈α
a
␈↓ ↓H␈↓mixed notation, e.g. ␈↓¬((A . B) (C . D) (3))␈↓.
␈↓ ↓H␈↓6␈↓ ¬oCHAPTER I␈↓ H


␈↓ ↓H␈↓        In␈α∞general,␈α∞the␈α∞list␈α
␈↓¬(A␈α∞B␈α∞.␈α∞.␈α∞.␈α
 Z)␈↓␈α∞may␈α∞be␈α∞regarded␈α
as␈α∞an␈α∞abbreviation␈α∞of␈α∞the␈α
S-expression
␈↓ ↓H␈↓␈↓¬(A . (B . (C . (... (Z . NIL) ...)))␈↓.


␈↓ ↓H␈↓α␈↓ ε
Exercises

␈↓ ↓H␈↓        1.␈αIf␈αwe␈αrepresent␈αsums␈αand␈αproducts␈αas␈αindicated␈α above␈α and␈αuse␈α ␈↓¬(MINUS␈αX),␈α (QUOTIENT␈αX
␈↓ ↓H␈↓¬Y)␈↓, and ␈↓¬(POWER X Y)␈↓  as representations of  ␈↓↓-x,␈↓  ␈↓↓x/y,␈↓ and  ␈↓↓x␈↓∧y␈↓  respectively, then

␈↓ ↓H␈↓        a. What do the lists

␈↓ ↓H␈↓                        ␈↓¬(QUOTIENT 2 (POWER (PLUS X (MINUS Y)) 3))␈↓

␈↓ ↓H␈↓and

␈↓ ↓H␈↓                        ␈↓¬(PLUS -2 (MINUS 2) (TIMES X (POWER Y 3.3)))␈↓

␈↓ ↓H␈↓represent?

␈↓ ↓H␈↓        b.    How    are    the   expressions   ␈↓↓xyz+3(u+v)␈↓∧-3␈↓   and ␈↓↓(xy-yx)/(xy+yx)␈↓ to be represented?

␈↓ ↓H␈↓        2. In the above  mentioned  graph  notation,  what  graph  is represented by the list

␈↓ ↓H␈↓        ␈↓¬((A D E F) (B D E F) (C D E F) (D A B C) (E A B C) (F A B C))␈↓?

␈↓ ↓H␈↓        3.␈αWrite␈αthe␈αlist␈α␈↓¬((PLUS␈α(TIMES␈αX␈αY)␈αX␈α3)␈↓␈αas␈αan␈αS-expression.␈α This␈αis␈αsometimes␈α
referred␈αto
␈↓ ↓H␈↓as "dot-notation".

␈↓ ↓H␈↓        4.  Write  the  following  S-expressions  in list notation to whatever extent is possible:

␈↓ ↓H␈↓        a. ␈↓¬(A . NIL)␈↓
␈↓ ↓H␈↓        b. ␈↓¬(A . B)␈↓
␈↓ ↓H␈↓        c. ␈↓¬((A . NIL) . B)␈↓
␈↓ ↓H␈↓        d. ␈↓¬((A . B) . ((C . D) . NIL)␈↓.

␈↓ ↓H␈↓        5.␈αProve␈αthat␈αthe␈αnumber␈αof␈α"shapes"␈αof␈αS-expressions␈αwith␈α␈↓↓n␈↓␈αatoms␈αis␈α␈↓↓(2n␈α-␈α2)!/(n!(n␈α-␈α1)!)␈↓.
␈↓ ↓H␈↓(The two shapes of S-expressions with three atoms are ␈↓¬(A.(B.C))␈↓ and ␈↓¬((A.B).C)␈↓.

␈↓ ↓H␈↓        6.␈αThe␈αabove␈αresult␈αcan␈αalso␈αbe␈αobtained␈αby␈αwriting␈α␈↓↓S = A + S␈↓αx␈↓↓S␈↓␈αas␈αan␈α"equation"␈αsatisfied
␈↓ ↓H␈↓by␈α∞the␈α∞set␈α∞of␈α
S-expressions␈α∞with␈α∞the␈α∞interpretation␈α
that␈α∞an␈α∞S-expression␈α∞is␈α
either␈α∞an␈α∞atom␈α∞or␈α
a
␈↓ ↓H␈↓pair␈αof␈α
S-expressions.␈α The␈αnext␈α
step␈αis␈α
to␈αregard␈αthe␈α
equation␈αas␈αthe␈α
quadratic␈α␈↓↓S␈↓∧2␈↓↓ - S + A␈α
=␈α0␈↓,
␈↓ ↓H␈↓solve␈α
it␈α
by␈α
the␈α
quadratic␈α
formula␈α
choosing␈α
the␈α
minus␈α
sign␈α
for␈α
the␈α
square␈α
root.␈α
 Then␈α
the␈αradical␈α
is
␈↓ ↓H␈↓regarded␈α
as␈α
the␈α
1/2␈α
power␈α
and␈α∞expanded␈α
by␈α
the␈α
binomial␈α
theorem.␈α
 Manipulating␈α∞the␈α
binomial
␈↓ ↓H␈↓coefficients␈α∞yields␈α∞the␈α∂above␈α∞formula␈α∞as␈α∞the␈α∂coefficient␈α∞of␈α∞␈↓↓A␈↓∧n␈↓␈α∞in␈α∂the␈α∞expansion.␈α∞ Why␈α∂does␈α∞this
␈↓ ↓H␈↓somewhat ill-motivated and irregular procedure give the right answer?

␈↓ ↓H␈↓        The last two exercises are unconnected with subsequent material in these notes.
␈↓ ↓H␈↓␈↓ ¬oCHAPTER I␈↓ 97


␈↓ ↓H␈↓5.  ␈↓αThe basic functions and predicates of LISP.␈↓


␈↓ ↓H␈↓        The␈α∞main␈α∞form␈α
of␈α∞LISP␈α∞program␈α
is␈α∞the␈α∞LISP␈α
function,␈α∞and␈α∞LISP␈α
functions␈α∞are␈α∞built␈α
up
␈↓ ↓H␈↓from␈α
basic␈αLISP␈α
functions,␈αpredicates,␈α
variables␈αand␈α
constants.␈α An␈α
expression␈αwith␈α
variables␈αin␈α
it
␈↓ ↓H␈↓whose␈α∩value␈α∪depends␈α∩on␈α∪the␈α∩values␈α∩of␈α∪the␈α∩variables␈α∪is␈α∩called␈α∩a␈α∪␈↓↓form.␈↓␈α∩ LISP␈α∪functions␈α∩are
␈↓ ↓H␈↓constructed␈α⊂from␈α⊂LISP␈α⊃␈↓↓forms␈↓␈α⊂which␈α⊂are␈α⊃written␈α⊂in␈α⊂two␈α⊃languages␈α⊂-␈α⊂␈↓↓publication␈↓␈α⊃␈↓↓language␈↓␈α⊂and
␈↓ ↓H␈↓␈↓↓internal␈↓␈α
␈↓↓language.␈↓␈α∞ Publication␈α
language␈α
is␈α∞easier␈α
for␈α∞people␈α
to␈α
read␈α∞and␈α
write,␈α∞but␈α
publication
␈↓ ↓H␈↓language␈αprograms␈αare␈αnot␈αS-expressions,␈αand␈αtherefore␈α
it␈αis␈αnot␈αeasy␈αto␈αwrite␈αLISP␈α
programs␈αto
␈↓ ↓H␈↓generate,␈α∩interpret␈α⊃or␈α∩compile␈α⊃other␈α∩LISP␈α⊃programs␈α∩when␈α⊃these␈α∩programs␈α⊃are␈α∩in␈α⊃publication
␈↓ ↓H␈↓language.␈α The␈α
internal␈αlanguage␈α
programs␈αare␈α
S-expressions␈αand␈α
are␈αharder␈α
for␈αa␈α
person␈αto␈α
read
␈↓ ↓H␈↓and␈αwrite,␈αbut␈αit␈αis␈αeasier␈α
for␈αa␈αperson␈αto␈αwrite␈αa␈α
program␈αto␈αmanipulate␈α␈↓↓object␈↓␈α␈↓↓programs␈↓␈αwhen␈α
the
␈↓ ↓H␈↓object␈α
programs␈α
are␈α
in␈α
internal␈α
language.␈α Besides␈α
all␈α
that,␈α
most␈α
LISP␈α
implementations␈αaccept␈α
only
␈↓ ↓H␈↓internal language programs rather than some form of publication language.

␈↓ ↓H␈↓        Just␈α∞as␈α∞numerical␈α∞computer␈α∞programs␈α∞are␈α
 based␈α∞ on␈α∞ the␈α∞ four␈α∞arithmetic␈α∞ operations␈α
 of
␈↓ ↓H␈↓addition␈α∂subtraction,␈α∂multiplication,␈α∂and␈α∂division,␈α∂and␈α∂the␈α∂arthmetic␈α∂predicates␈α∂of␈α∂equality␈α∂and
␈↓ ↓H␈↓comparison,␈α∂so␈α∂symbolic␈α∂ computation␈α∞ has␈α∂ its␈α∂basic␈α∂predicates␈α∞and␈α∂functions.␈α∂ LISP␈α∂has␈α∞three
␈↓ ↓H␈↓basic␈αfunctions␈αand␈αtwo␈αpredicates.␈α Each␈αwill␈αbe␈αexplained␈αfirst␈αin␈αits␈αpublication␈αform,␈αand␈αthen
␈↓ ↓H␈↓the internal form will be given.

␈↓ ↓H␈↓        First,␈α⊂ we␈α⊂have␈α⊂two␈α∂functions␈α⊂␈↓αa␈↓␈α⊂and␈α⊂␈↓αd␈↓.␈α∂ ␈↓αa␈↓␈α∧␈↓↓x␈↓␈α⊂is␈α⊂the␈α⊂a-part␈α∂of␈α⊂the␈α⊂S-expression␈α⊂␈↓↓x.␈↓␈α∂ Thus,
␈↓ ↓H␈↓␈↓αa␈↓␈α∧␈↓¬(A . B) = A␈↓,␈αand␈α␈↓αa␈↓␈α∧␈↓¬((A . B) . A) = (A . B)␈↓.␈α ␈↓αd␈↓␈α∧␈↓↓x␈↓␈αis␈αthe␈αd-part␈αof␈αthe␈αS-expression␈α␈↓↓x.␈↓␈αThus␈α␈↓αd␈↓␈α∧␈↓¬(A . B) = B␈↓,
␈↓ ↓H␈↓and␈α␈↓αd␈↓␈α∧␈↓¬((A . B) . A) = A␈↓.␈α
 ␈↓αa␈↓␈α∧␈↓↓x␈↓␈αand␈α␈↓αd␈↓␈α∧␈↓↓x␈↓␈α
are␈αundefined␈αin␈α
basic␈αLISP␈αwhen␈α
␈↓↓x␈↓␈αis␈αan␈α
atom,␈αbut␈α
they␈αmay
␈↓ ↓H␈↓have␈α∂a␈α⊂meaning␈α∂in␈α∂some␈α⊂implementations.␈α∂ The␈α∂internal␈α⊂forms␈α∂of␈α∂␈↓αa␈↓␈α∧␈↓↓x␈↓␈α⊂and␈α∂␈↓αd␈↓␈α∧␈↓↓x␈↓␈α∂are␈α⊂␈↓¬(CAR X)␈↓␈α∂and
␈↓ ↓H␈↓␈↓¬(CDR X)␈↓␈αrespectively.␈α The␈αnames␈α␈↓¬CAR␈α
␈↓and␈α␈↓¬CDR␈α␈↓␈αstood␈αfor␈α
"contents␈αof␈αthe␈αaddress␈αpart␈αof␈α
register"
␈↓ ↓H␈↓and␈α∞"contents␈α∞of␈α∞the␈α∞decrement␈α∞part␈α∞of␈α∞register"␈α∞in␈α∞a␈α∞1957␈α∞precursor␈α∞of␈α∞LISP␈α∞projected␈α∞for␈α∞the
␈↓ ↓H␈↓IBM 704 computer.  The names have persisted for lack of a clearly preferable alternative.

␈↓ ↓H␈↓        A␈α⊂certain␈α⊂ambiguity␈α⊂arises␈α⊃when␈α⊂we␈α⊂want␈α⊂to␈α⊃use␈α⊂S-expression␈α⊂constants␈α⊂in␈α⊃the␈α⊂internal
␈↓ ↓H␈↓language.␈α∂ Namely,␈α∂the␈α∂S-expression␈α∂␈↓¬A␈α∞␈↓␈α∂could␈α∂either␈α∂stand␈α∂for␈α∞itself␈α∂or␈α∂stand␈α∂for␈α∂a␈α∂variable␈α∞␈↓¬A
␈↓ ↓H␈↓¬␈↓whose␈αvalue␈αis␈α
wanted.␈α Even␈α␈↓¬(CAR␈αX)␈↓␈α
is␈αambiguous␈αsince␈α
sometime␈αthe␈αS-expression␈α␈↓¬(CAR X)␈↓␈α
itself
␈↓ ↓H␈↓must␈α
be␈αreferred␈α
to␈α
and␈αnot␈α
the␈αresult␈α
of␈α
evaluating␈αit.␈α
 Internal␈α
language␈αavoids␈α
the␈αambiguity␈α
by
␈↓ ↓H␈↓using␈α⊃␈↓¬(QUOTE ␈↓↓e␈↓¬)␈↓␈α⊃to␈α⊃stand␈α⊂for␈α⊃the␈α⊃S-expression␈α⊃␈↓↓e.␈↓␈α⊂Thus␈α⊃the␈α⊃publication␈α⊃language␈α⊃form␈α⊂␈↓αa␈↓␈α∧␈↓¬(A B)␈↓
␈↓ ↓H␈↓corresponds␈α∀to␈α∀the␈α∪internal␈α∀language␈α∀form␈α∪␈↓¬(CAR (QUOTE (A B)))␈↓␈α∀and␈α∀both␈α∪have␈α∀the␈α∀value␈α∪␈↓¬A
␈↓ ↓H␈↓¬␈↓obtained by taking the a-part of the S-expression ␈↓¬(A B)␈↓.

␈↓ ↓H␈↓        Since␈α
 lists␈α
 are␈α
 a␈α
 particular␈α
 kind␈α
 of␈α S-expression,␈α
the␈α
meanings␈α
of␈α
␈↓αa␈↓␈α
 and␈α
 ␈↓αd␈↓␈α
 for␈αlists
␈↓ ↓H␈↓are also determined  by  the  above definitions.  Thus, we have

␈↓ ↓H␈↓␈↓ ¬>␈↓↓␈↓αa␈↓↓␈α∧␈↓¬(A B C D)␈↓↓ = ␈↓¬A ␈↓↓        ␈↓ 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ ¬>␈↓↓␈↓αd␈↓↓␈α∧␈↓¬(A B C D)␈↓↓ = ␈↓¬(B C D)␈↓↓,␈↓ 

␈↓ ↓H␈↓and␈αwe␈αsee␈αthat,␈αin␈αgeneral,␈α ␈↓αa␈↓␈α∧␈↓↓x␈↓␈α is␈αthe␈αfirst␈αelement␈α
of␈α the␈α list␈α ␈↓↓x,␈↓␈αand␈α ␈↓αd␈↓␈α∧␈↓↓x␈↓␈α is␈αthe␈αrest␈αof␈αthe␈α
list,
␈↓ ↓H␈↓deleting that first element.
␈↓ ↓H␈↓8␈↓ ¬oCHAPTER I␈↓ H


␈↓ ↓H␈↓        Notice␈α∞ that␈α∞ for␈α∞S-expressions,␈α
the␈α∞definitions␈α∞of␈α∞ ␈↓αa␈↓␈α∧␈↓↓x␈↓␈α
 and␈α∞␈↓αd␈↓␈α∧␈↓↓x␈↓␈α∞ are␈α∞symmetrical,␈α∞while␈α
for
␈↓ ↓H␈↓lists␈α
the␈α
symmetry␈αis␈α
lost.␈α
 This␈α
is␈αbecause␈α
 of␈α
 the␈α
 unsymmetrical␈αnature␈α
of␈α
the␈α
convention␈αthat
␈↓ ↓H␈↓defines lists in terms of S-expressions.

␈↓ ↓H␈↓        Notice,␈αfurther,␈α our␈α convention␈α of␈α writing␈α  ␈↓αa␈↓␈α  and␈α  ␈↓αd␈↓  ␈αwithout␈α brackets␈α surrounding
␈↓ ↓H␈↓the␈αargument.␈α Also,␈αwe␈αuse␈αlower␈αcase␈αletters␈αfor␈αour␈αfunction␈αnames␈αand␈αfor␈αvariables,␈αreserving
␈↓ ↓H␈↓the upper case letters for the S-expressions themselves.

␈↓ ↓H␈↓        The␈α∞ third␈α∞ function␈α∞ ␈↓↓cons[x,␈α∞y]␈↓␈α∞ forms␈α
the␈α∞S-expression␈α∞whose␈α∞a-part␈α∞and␈α∞d-part␈α∞are␈α
 ␈↓↓x␈↓
␈↓ ↓H␈↓and  ␈↓↓y␈↓  respectively.  Thus

␈↓ ↓H␈↓␈↓ ¬.␈↓↓cons[␈↓¬(A.B), A␈↓↓] = ␈↓¬((A.B).A)␈↓↓␈↓. 

␈↓ ↓H␈↓        We␈α∞ see␈α∞ that␈α∞ for␈α∂ lists,␈α∞  ␈↓↓cons␈↓␈α∞  is␈α∞a␈α∞prefixing␈α∂operation.␈α∞ Namely,␈α∞ ␈↓↓cons[x,␈α∞y]␈↓␈α∞ is␈α∂the␈α∞list
␈↓ ↓H␈↓obtained by putting the  element   ␈↓↓x␈↓  onto the front of the list  ␈↓↓y.␈↓  Thus

␈↓ ↓H␈↓␈↓ ∧}␈↓↓cons[␈↓¬A, (B C D E)␈↓↓] = ␈↓¬(A B C D E)␈↓↓␈↓. 

␈↓ ↓H␈↓If␈α
we␈α
want␈α ␈↓↓cons[x,␈α
y]␈↓␈α
 to␈α be␈α
 a␈α
 list,␈α
 then␈α  ␈↓↓y␈↓␈α
  must␈α
 be␈α a␈α
 list␈α
(possibly␈α
the␈αnull␈α
list␈α
 ␈↓¬NIL␈↓),␈αand␈α
 ␈↓↓x␈↓
␈↓ ↓H␈↓must␈αbe␈αa␈αlist␈αor␈αan␈αatom.␈α In␈αthe␈αcase␈αof␈αS-expressions␈αin␈αgeneral,␈αthere␈αis␈αno␈αrestriction␈αon␈α the
␈↓ ↓H␈↓arguments␈α⊂ of␈α⊂  ␈↓↓cons.␈↓␈α⊃  Usually,␈α⊂ we␈α⊂ shall␈α⊃ write␈α⊂  ␈↓↓x␈α⊂.␈α⊃y␈↓␈α⊂  instead␈α⊂of␈α⊃␈↓↓cons[x,␈α⊂y]␈↓␈α⊂ since␈α⊃this␈α⊂is
␈↓ ↓H␈↓briefer.

␈↓ ↓H␈↓        The␈α
internal␈α∞language␈α
form␈α∞of␈α
␈↓↓cons[x,␈α∞y]␈↓␈α
is␈α∞␈↓¬(CONS␈α
X␈α∞Y)␈↓.␈α
 The␈α∞name␈α
"CONS"␈α∞comes␈α
from
␈↓ ↓H␈↓"construct" referring to the way ␈↓↓cons[x, y]␈↓ is constructed from the free storage list.

␈↓ ↓H␈↓        The␈α∞ first␈α∞ predicate␈α∞ is␈α∞  ␈↓αat␈↓.␈α∞  ␈↓αat␈↓␈αε␈↓↓x␈↓␈α∞  is␈α∞ true␈α∞ if␈α∞  the␈α∞S-expression␈α∞ ␈↓↓x␈↓␈α∞ is␈α∞atomic␈α∂and␈α∞false
␈↓ ↓H␈↓otherwise.  The internal form is ␈↓¬(ATOM X)␈↓.

␈↓ ↓H␈↓        The␈α∩ second␈α∩ predicate␈α∩ is␈α∪equality␈α∩of␈α∩atomic␈α∩symbols␈α∩written␈α∪␈↓↓x␈↓␈α∩␈↓αeq␈↓␈α∩␈↓↓y.␈↓␈α∩Equality␈α∪of␈α∩S-
␈↓ ↓H␈↓expressions␈α
is␈α
tested␈α
by␈α
a␈α
 program␈α
 based␈α
 on␈α␈↓αeq␈↓.␈α
  Actually␈α
  ␈↓αeq␈↓␈α
  does␈α
a␈α
bit␈α
more␈α
than␈αtesting
␈↓ ↓H␈↓equality␈α
of␈α
atoms.␈α
 Namely,␈α
 ␈↓↓x␈↓␈α
␈↓αeq␈↓␈α
␈↓↓y␈↓␈α
 is␈α
true␈α
if␈α
and␈α
only␈α
if␈α
the␈α
addresses␈α
 of␈α
 the␈α
 first␈α
words␈α of
␈↓ ↓H␈↓the␈α list␈αstructures␈α  ␈↓↓x␈↓␈α  and␈α ␈↓↓y␈↓␈α are␈αequal.␈α Therefore,␈αif␈α␈↓↓x␈↓␈α␈↓αeq␈↓␈α␈↓↓y,␈↓␈αthen␈α ␈↓↓x␈↓␈α and␈α␈↓↓y␈↓␈αare␈αcertainly␈α the
␈↓ ↓H␈↓same␈α S-expression␈α since␈αthey␈α are␈α represented␈αby␈αthe␈αsame␈αstructure␈αin␈αmemory.␈α The␈αconverse
␈↓ ↓H␈↓is␈α
false␈α
because␈αthere␈α
is␈α
no␈α
 guarantee␈α in␈α
 general␈α
 that␈α
 the␈α same␈α
S-expression␈α
is␈αnot␈α
represented
␈↓ ↓H␈↓by␈α
two␈α
different␈α
list␈α
structures.␈α
 In␈α
the␈α
particular␈αcase␈α
where␈α
at␈α
least␈α
one␈α
of␈α
the␈α
S-expressions␈αis
␈↓ ↓H␈↓known␈α
to␈α be␈α
 an␈α
atom,␈αthis␈α
guarantee␈αcan␈α
be␈α
given,␈αbecause␈α
LISP␈αrepresents␈α
atoms␈α
uniquely␈αin
␈↓ ↓H␈↓memory.  The internal form is ␈↓¬(EQ X Y)␈↓.

␈↓ ↓H␈↓        The␈α∂above␈α∂are␈α∂all␈α⊂the␈α∂basic␈α∂functions␈α∂of␈α∂LISP;␈α⊂all␈α∂other␈α∂LISP␈α∂functions␈α∂ can␈α⊂ be␈α∂ built
␈↓ ↓H␈↓from␈α
 them␈α
 using␈α
 recursive␈α
 conditional␈α
expressions␈α
as␈α
will␈α
shortly␈α
be␈α
explained.␈α∞However,␈α
the
␈↓ ↓H␈↓use of certain abbreviations makes LISP programs easier to write and understand.

␈↓ ↓H␈↓        ␈↓αn␈↓␈α∧␈↓↓x␈↓␈α∞  is␈α
 an␈α∞ abbreviation␈α∞for␈α
 ␈↓↓x␈↓␈α∞␈↓αeq␈↓␈α∞␈↓¬NIL␈↓.␈α
 It␈α∞rates␈α
a␈α∞special␈α∞notation␈α
because␈α∞ ␈↓¬NIL␈↓␈α∞ plays␈α
the
␈↓ ↓H␈↓same␈α
 role␈α
 among␈α
 lists␈α∞ that␈α
 zero␈α
plays␈α
 among␈α
 numbers,␈α∞ and␈α
list␈α
variables␈α
often␈α
have␈α∞to␈α
be
␈↓ ↓H␈↓tested to see if their value is  ␈↓¬NIL␈↓.  Its internal form is ␈↓¬(NULL X)␈↓.
␈↓ ↓H␈↓␈↓ ¬oCHAPTER I␈↓ 99


␈↓ ↓H␈↓    The␈αnotation␈α␈↓↓list[x1,␈αx2,␈α.␈α.␈α.␈α,␈αxn]␈↓␈αis␈αused␈αto␈αdenote␈αthe␈αcomposition␈αof␈α␈↓↓cons␈↓'s␈αthat␈αforms␈αa
␈↓ ↓H␈↓list from its elements.  Thus

␈↓ ↓H␈↓␈↓ ∧-␈↓↓list[x, y, z] = cons[x, cons[y, cons[z, ␈↓¬NIL␈↓↓]]]␈↓ 

␈↓ ↓H␈↓and␈α
forms␈α
a␈α
list␈α
of␈α
three␈α
elements␈α
out␈α
of␈α
the␈α
quantities␈α␈↓↓x,␈↓␈α
␈↓↓y,␈↓␈α
 and␈α
␈↓↓z.␈↓␈α
 We␈α
often␈α
write␈α
␈↓↓<x␈α
y␈α
.␈α
.␈α.␈α
z>␈↓
␈↓ ↓H␈↓instead␈αof␈α␈↓↓list[x,␈αy,␈α.␈α .␈α.␈α,␈α
z]␈↓␈αwhen␈αthis␈αwill␈αnot␈αcause␈αconfusion.␈α The␈αexperienced␈α
implementer
␈↓ ↓H␈↓of␈α∂programming␈α∂languages␈α⊂will␈α∂expect␈α∂that␈α⊂since␈α∂␈↓↓list␈↓␈α∂has␈α∂a␈α⊂variable␈α∂number␈α∂of␈α⊂arguments,␈α∂its
␈↓ ↓H␈↓implementation␈α∪will␈α∪pose␈α∪problems.␈α∪ He␈α∪will␈α∀be␈α∪right.␈α∪ The␈α∪internal␈α∪form␈α∪of␈α∀␈↓↓<x y ... z>␈↓␈α∪is
␈↓ ↓H␈↓␈↓¬(LIST X Y ...Z)␈↓.

␈↓ ↓H␈↓        Compositions␈αof␈α␈↓αa␈↓␈αand␈α␈↓αd␈↓␈αare␈αwritten␈αby␈αconcatenating␈αthe␈αletters␈α␈↓αa␈↓␈αand␈α␈↓αd␈↓.␈α Thus,␈αit␈αis␈αeasily
␈↓ ↓H␈↓seen␈αthat␈α␈↓αad␈↓␈α∧␈↓↓x␈↓␈α
denotes␈αthe␈αsecond␈α
element␈αof␈αthe␈α
list␈α␈↓↓x,␈↓␈αand␈α
␈↓αadd␈↓␈α∧␈↓↓x␈↓␈αdenotes␈αthe␈α
third␈αelement␈αof␈α
that
␈↓ ↓H␈↓list.  The internal forms of these functions are ␈↓¬CADR ␈↓ and ␈↓¬CADDR ␈↓respectively.

␈↓ ↓H␈↓        Besides␈α
the␈α
basic␈α
functions␈αof␈α
LISP,␈α
there␈α
will␈αbe␈α
user-defined␈α
functions.␈α
 We␈αhaven't␈α
given
␈↓ ↓H␈↓the␈α
mechanism␈α
function␈α
definition␈α
yet,␈α
but␈α
suppose␈α
a␈α
function␈α
␈↓↓subst␈↓␈α
taking␈α
three␈α∞arguments␈α
has
␈↓ ↓H␈↓been defined.  It may be used in forms like ␈↓↓subst[x,y,z]␈↓ having internal form ␈↓¬(SUBST X Y Z)␈↓.

␈↓ ↓H␈↓        As␈α∩in␈α∩other␈α∩programming␈α∩languages␈α∪and␈α∩in␈α∩mathematics␈α∩generally,␈α∩new␈α∩forms␈α∪can␈α∩be
␈↓ ↓H␈↓constructed␈αby␈αapplying␈αthe␈αfunctions␈αand␈αpredicates␈αto␈αother␈αforms␈αand␈αnot␈αjust␈αto␈αvariables␈αand
␈↓ ↓H␈↓constants.␈α∩ Thus␈α∩we␈α∩have␈α∩forms␈α∩like␈α⊃␈↓↓subst[x,y,␈↓αa␈↓↓␈α∧z]␈α∩.␈α∩subst[x,y,␈↓αd␈↓↓␈α∧z]␈↓␈α∩involving␈α∩a␈α∩user␈α⊃defined
␈↓ ↓H␈↓function ␈↓↓subst.␈↓  Its internal form is ␈↓¬(CONS (SUBST X Y (CAR Z)) (SUBST X Y (CDR Z)))␈↓.

␈↓ ↓H␈↓        In␈αpublication␈αlanguage,␈αwe␈αoften␈αomit␈αbrackets␈αfor␈αfunctions␈αof␈αone␈αargument.␈α Thus␈α␈↓↓alt x␈↓
␈↓ ↓H␈↓stands for ␈↓↓alt[x]␈↓, and ␈↓↓alt alt x␈↓ stands for ␈↓↓alt[alt[x]]␈↓.



␈↓ ↓H␈↓6.  ␈↓αConditional expressions.␈↓


␈↓ ↓H␈↓        When␈α
the␈α
form␈α
that␈α
represents␈α
a␈α
function␈α
depends␈α
on␈α
whether␈α
a␈α
certain␈α
 predicate␈α
is␈αtrue␈α
of
␈↓ ↓H␈↓the␈α∪arguments,␈α∩conditional␈α∪expressions␈α∩are␈α∪used.␈α∩ The␈α∪conditional␈α∩expression␈α∪(more␈α∩properly
␈↓ ↓H␈↓␈↓↓conditional form␈↓)

␈↓ ↓H␈↓␈↓ ¬/␈↓↓␈↓αif␈↓↓ p ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b        ␈↓ 

␈↓ ↓H␈↓is␈α
evaluated␈α
as␈αfollows:␈α
 First␈α
 ␈↓↓p␈↓␈α is␈α
evaluated␈α
and␈αdetermined␈α
to␈α
be␈αtrue␈α
or␈α
false.␈α If␈α
 ␈↓↓p␈↓␈α
 is␈αtrue,
␈↓ ↓H␈↓then␈α
 ␈↓↓a␈↓␈α
 is␈αevaluated␈α
and␈α
 its␈α value␈α
is␈α
 the␈α value␈α
 of␈α
 the␈α expression.␈α
  If␈α
  ␈↓↓p␈↓␈α  is␈α
false,␈α
then␈α ␈↓↓b␈↓␈α
 is
␈↓ ↓H␈↓evaluated␈α⊃and␈α⊃its␈α⊂value␈α⊃is␈α⊃the␈α⊂value␈α⊃of␈α⊃the␈α⊂expression.␈α⊃ Note␈α⊃that␈α⊂if␈α⊃␈↓↓p␈↓␈α⊃ is␈α⊂true,␈α⊃ ␈↓↓b␈↓␈α⊃ is␈α⊂never
␈↓ ↓H␈↓evaluated,␈α∩and␈α∩if␈α∩ ␈↓↓p␈↓␈α∩ is␈α∩false,␈α∩then␈α∩ ␈↓↓a␈↓␈α∩ is␈α∩never␈α∩evaluated.␈α∩ The␈α∩importance␈α∩of␈α∩this␈α∪will␈α∩be
␈↓ ↓H␈↓explained␈α⊗ later.␈α⊗ A␈α∃familiar␈α⊗ function␈α⊗that␈α⊗can␈α∃be␈α⊗written␈α⊗conveniently␈α⊗using␈α∃conditional
␈↓ ↓H␈↓expressions is the absolute value of a real number.  We have

␈↓ ↓H␈↓␈↓ ¬≤␈↓↓|x| = ␈↓αif␈↓↓ x<0 ␈↓αthen␈↓↓ -x ␈↓αelse␈↓↓ x␈↓. 

␈↓ ↓H␈↓An extended form of conditional expression is
␈↓ ↓H␈↓10␈↓ ¬oCHAPTER I␈↓ H


␈↓ ↓H␈↓␈↓ β↑␈↓↓␈↓αif␈↓↓ p ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ ␈↓αif␈↓↓ q ␈↓αthen␈↓↓ b . . .  ␈↓αelse␈↓↓ ␈↓αif␈↓↓ s ␈↓αthen␈↓↓ d ␈↓αelse␈↓↓ e␈↓. 

␈↓ ↓H␈↓There␈α
 can␈α
 be␈α
 any␈α
 number␈α
 of␈α
 terms;␈α
 the␈α
 value␈α
 is␈α
determined␈α
by␈α
evaluating␈αthe␈α
propositional
␈↓ ↓H␈↓terms␈α
 ␈↓↓p,␈↓␈α
 ␈↓↓q,␈↓␈α
etc.␈α
until␈α
a␈α
true␈α
term␈α
 is␈αfound;␈α
 the␈α
value␈α
is␈α
then␈α
that␈α
of␈α
the␈α
term␈α
following␈αthe␈α
next
␈↓ ↓H␈↓␈↓αthen␈↓.␈α If␈αnone␈αof␈αthe␈α
propositional␈αterms␈αis␈αtrue,␈αthen␈αthe␈α
value␈αis␈αthat␈αof␈αthe␈αterm␈α
following␈αthe
␈↓ ↓H␈↓␈↓αelse␈↓.

␈↓ ↓H␈↓        The function graphed in figure 4 is described by the equation

␈↓ ↓H␈↓␈↓ αw␈↓↓tri[x] = ␈↓αif␈↓↓ x<-1 ␈↓αthen␈↓↓ 0 ␈↓αelse␈↓↓ ␈↓αif␈↓↓ x<0 ␈↓αthen␈↓↓ 1+x ␈↓αelse␈↓↓ ␈↓αif␈↓↓ x<1 ␈↓αthen␈↓↓ 1-x ␈↓αelse␈↓↓ 0␈↓. 




␈↓"␈↓ ↓H␈↓                                   (0,1)
␈↓"␈↓ ↓H␈↓                                 ≤'`≥
␈↓"␈↓ ↓H␈↓                               ≤'    `≥
␈↓"␈↓ ↓H␈↓                             ≤'        `≥
␈↓"␈↓ ↓H␈↓                           ≤'            `≥
␈↓"␈↓ ↓H␈↓          αααααααααααααααα'                `αααααααααααααααα
␈↓"␈↓ ↓H␈↓                       (-1,0)            (1,0)




␈↓ ∧␈↓ ↓H␈↓                               Figure 4.


␈↓ ↓H␈↓        The␈αinternal␈αform␈αof␈αconditional␈α
forms␈αis␈αmade␈αin␈αa␈α
more␈αregular␈αway␈αthan␈αthe␈α
publication
␈↓ ↓H␈↓form; the publication form was altered to conform to ALGOL.  We write

␈↓ ↓H␈↓␈↓ ∧o␈↓↓␈↓¬(COND ␈↓↓(p1 e1) (p2 e2) ... (pn en)␈↓¬)␈↓↓␈↓ 

␈↓ ↓H␈↓with␈αany␈αnumber␈αof␈αterms.␈α Its␈αvalue␈αis␈αdetermined␈αby␈αevaluating␈αthe␈α␈↓↓p␈↓'s␈αsuccessively␈αuntil␈αone␈αis
␈↓ ↓H␈↓found␈α∀which␈α∀is␈α∀true.␈α∀ Then␈α∀the␈α∀corresponding␈α∪␈↓↓e␈↓␈α∀is␈α∀taken␈α∀as␈α∀the␈α∀value␈α∀of␈α∀the␈α∪conditional
␈↓ ↓H␈↓expression.␈α If␈α
none␈αof␈α
the␈α␈↓↓p␈↓'s␈α
is␈αtrue,␈αthen␈α
the␈αvalue␈α
of␈αthe␈α
conditional␈αexpression␈α
is␈αundefined.
␈↓ ↓H␈↓Thus␈α∪all␈α∩the␈α∪␈↓↓e␈↓'s␈α∩are␈α∪treated␈α∩the␈α∪same␈α∩which␈α∪makes␈α∩programs␈α∪for␈α∩interpreting␈α∪or␈α∩compiling
␈↓ ↓H␈↓conditional␈αexpressions␈αeasier␈αto␈α
write.␈α Putting␈αparentheses␈αaround␈α
each␈α␈↓↓p-e␈↓␈αpair␈αwas␈αprobably␈α
a
␈↓ ↓H␈↓mistake␈αin␈αthe␈αdesign␈αof␈αLISP,␈αbecause␈αit␈αunnecessarily␈αincreases␈αthe␈αnumber␈αof␈αright␈α
parentheses.
␈↓ ↓H␈↓It␈αshould␈αhave␈αbeen␈α ␈↓¬(COND␈α␈↓↓p1␈αe1␈αp2␈αe2␈α...␈αpn␈αen␈↓),␈αbut␈αsuch␈αa␈αchange␈αshould␈αbe␈αmade␈αnow␈αonly
␈↓ ↓H␈↓as part of a massive improvement.

␈↓ ↓H␈↓        Conditional expressions may be compounded with functions to get forms like

␈↓ ↓H␈↓␈↓ ∧N␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧x . append[␈↓αd␈↓↓␈α∧x, y]␈↓ 

␈↓ ↓H␈↓involving a yet to be defined function ␈↓↓append.␈↓  The internal form of this is
␈↓ ↓H␈↓␈↓ ¬oCHAPTER I␈↓ *11


␈↓ ↓H␈↓␈↓ βA␈↓↓␈↓¬(COND ((NULL X) NIL) (T (CONS (CAR X) (APPEND (CDR X) Y))))␈↓↓.␈↓ 

␈↓ ↓H␈↓One␈α∂would␈α∂normally␈α∞have␈α∂expected␈α∂to␈α∞write␈α∂␈↓¬(QUOTE␈α∂NIL)␈↓␈α∞and␈α∂␈↓¬(QUOTE␈α∂T)␈↓,␈α∞but␈α∂there␈α∂is␈α∂a␈α∞special
␈↓ ↓H␈↓convention␈αthat␈α␈↓¬NIL␈↓␈αand␈α␈↓¬T␈↓␈αmay␈αbe␈αwritten␈αwithout␈α␈↓¬QUOTE.␈α␈↓␈αThis␈αmeans␈αthat␈αthese␈αsymbols␈αcannot
␈↓ ↓H␈↓be␈α
used␈α
as␈α
variables.␈α
 The␈α
value␈α
of␈α
␈↓¬T␈↓␈α
is␈α
the␈α
propositional␈α
constant␈α
␈↓αtrue␈↓,␈α
i.e.␈α
it␈α
is␈α
always␈α
true␈α
so␈α
that
␈↓ ↓H␈↓it␈α∞is␈α∞impossible␈α∂to␈α∞"fall␈α∞off␈α∞the␈α∂end"␈α∞of␈α∞a␈α∞conditional␈α∂expression␈α∞with␈α∞␈↓¬T␈↓␈α∞as␈α∂its␈α∞last␈α∞␈↓↓p.␈↓␈α∞ It␈α∂is␈α∞the
␈↓ ↓H␈↓translation into internal form of the final ␈↓αelse␈↓ of a conditional expression.



␈↓ ↓H␈↓7.  ␈↓αBoolean expressions.␈↓


␈↓ ↓H␈↓        In␈α⊃ making␈α⊃ up␈α⊃ the␈α⊃ propositional␈α⊂  parts␈α⊃  of␈α⊃  conditional␈α⊃expressions,␈α⊃  it␈α⊃  is␈α⊂  often
␈↓ ↓H␈↓necessary␈α
  to␈α
  combine␈α
 elementary␈α
propositional␈α
expressions␈α
using␈α
the␈α
Boolean␈α
operators␈α
 and,
␈↓ ↓H␈↓or,␈α⊃ and␈α⊃not.␈α∩  We␈α⊃ use␈α⊃ the␈α⊃ symbols␈α∩  ∧,␈α⊃ ∨,␈α⊃and␈α⊃ ¬␈α∩ respectively,␈α⊃for␈α⊃these␈α∩operators.␈α⊃ The
␈↓ ↓H␈↓Boolean␈α∩operators␈α∩may␈α⊃be␈α∩described␈α∩simply␈α⊃by␈α∩listing␈α∩the␈α⊃values␈α∩of␈α∩the␈α∩elementary␈α⊃Boolean
␈↓ ↓H␈↓expressions for  each  case  of  the arguments.  Thus we have:

␈↓ ↓H␈↓                                T∧T = T
␈↓ ↓H␈↓                                T∧F = F
␈↓ ↓H␈↓                                F∧T = F
␈↓ ↓H␈↓                                F∧F = F

␈↓ ↓H␈↓                                T∨T = T
␈↓ ↓H␈↓                                T∨F = T
␈↓ ↓H␈↓                                F∨T = T
␈↓ ↓H␈↓                                F∨F = F

␈↓ ↓H␈↓                                ¬T = F
␈↓ ↓H␈↓                                ¬F = T.

␈↓ ↓H␈↓        Since␈α
both␈α∧␈α
and␈α
∨␈αare␈α
associative␈α
we␈αcan␈α
write␈α
Boolean␈αforms␈α
like␈α
␈↓↓p1 ∧ p2 ∧ p3␈↓␈αwithout
␈↓ ↓H␈↓worrying␈α⊃about␈α∩grouping.␈α⊃ The␈α⊃internal␈α∩forms␈α⊃are␈α⊃␈↓¬(AND ␈↓↓p1 p2 ... pn␈↓¬)␈↓,␈α∩␈↓¬(OR ␈↓↓p1 p2 ... pn␈↓¬)␈↓␈α⊃and
␈↓ ↓H␈↓␈↓¬(NOT ␈↓↓p␈↓¬)␈↓.␈α It␈αis␈αalso␈αcustomary␈αto␈αuse␈α␈↓¬NIL␈↓␈αinstead␈αof␈α␈↓¬F,␈α␈↓because␈αin␈αmost␈αLISP␈αsystems␈αboth␈αBoolean
␈↓ ↓H␈↓␈↓αfalse␈↓␈αand␈αthe␈αnull␈αlist␈αare␈αrepresented␈αby␈α
the␈αnumber␈α0.␈α This␈αmakes␈αcertain␈αtests␈αrun␈α
faster,␈αbut
␈↓ ↓H␈↓introduces so many complications in implementation that it was certainly a bad idea.

␈↓ ↓H␈↓        The␈α
 Boolean␈α
 operators␈α
 can␈α
 be␈α
 described␈α
 by␈α
  conditional␈α
expressions␈α
in␈α
the␈αfollowing
␈↓ ↓H␈↓way:

␈↓ ↓H␈↓␈↓ ¬(␈↓↓p∧q = ␈↓αif␈↓↓ p ␈↓αthen␈↓↓ q ␈↓αelse␈↓↓ ␈↓¬F ␈↓↓␈↓ 

␈↓ ↓H␈↓␈↓ ¬,␈↓↓p∨q = ␈↓αif␈↓↓ p ␈↓αthen␈↓↓ ␈↓¬T␈↓↓ ␈↓αelse␈↓↓ q␈↓ 

␈↓ ↓H␈↓␈↓ ¬(␈↓↓¬p = ␈↓αif␈↓↓ p ␈↓αthen␈↓↓ ␈↓¬F ␈↓↓␈↓αelse␈↓↓ ␈↓¬T␈↓↓ ␈↓. 
␈↓ ↓H␈↓12␈↓ ¬oCHAPTER I␈↓ H


␈↓ ↓H␈↓Note␈α
that␈α
if␈α
 ␈↓↓p␈↓␈α
 is␈α
false␈α
 ␈↓↓p ∧ q␈↓␈α
 is␈α
false␈α
independent␈α
of␈α
the␈α
value␈α
 of␈α
␈↓↓q,␈↓␈α
 and␈α
 likewise␈α
 if␈α∞ ␈↓↓p␈↓␈α
 is
␈↓ ↓H␈↓true,␈αthen␈α ␈↓↓p ∨ q␈↓␈α is␈αtrue␈αindependent␈αof␈α␈↓↓q.␈↓␈α If␈α ␈↓↓p␈↓␈α has␈αbeen␈αevaluated␈αand␈αfound␈αto␈αbe␈αfalse,␈α
then
␈↓ ↓H␈↓␈↓↓q␈↓␈α  does␈αnot␈α have␈α to␈α be␈αevaluated␈αat␈αall␈αto␈αfind␈αthe␈αvalue␈αof␈α ␈↓↓p ∧ q␈↓,␈αand,␈αin␈αfact,␈αLISP␈αdoes␈αnot
␈↓ ↓H␈↓evaluate␈α ␈↓↓q␈↓␈α in␈αthis␈αcase.␈α Similarly,␈α ␈↓↓q␈↓␈α is␈α
not␈αevaluated␈α in␈α evaluating␈α  ␈↓↓p ∨ q␈↓␈α if␈α ␈↓↓p␈↓␈α is␈αtrue.␈α
This
␈↓ ↓H␈↓procedure␈α∂is␈α∂in␈α∂accordance␈α∂with␈α∂the␈α∂above␈α∂conditional␈α∂expression␈α∂descriptions␈α∂of␈α⊂ the␈α∂Boolean
␈↓ ↓H␈↓operators.␈α The␈αimportance␈αof␈αthis␈αconvention␈αwhich␈αcontrasts␈αwith␈αthat␈αof␈αALGOL␈α 60,␈α will␈α be
␈↓ ↓H␈↓apparent  later  when  we  discuss recursive definitions of functions and predicates.

␈↓ ↓H␈↓        Boolean␈α⊂expressions␈α⊂can␈α⊂be␈α⊂combined␈α⊂with␈α⊂functions␈α⊂and␈α⊂conditional␈α⊂expressions␈α⊃to␈α⊂get
␈↓ ↓H␈↓forms like

␈↓ ↓H␈↓␈↓ ∧↑␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ∨ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧x ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧x . alt ␈↓αdd␈↓↓␈α∧x␈↓ 

␈↓ ↓H␈↓the internal form of which is

␈↓ ↓H␈↓␈↓ αj␈↓↓␈↓¬(COND ((OR (NULL X) (NULL (CDR X))) X) (T (CONS (CAR X) (ALT (CDDR X)))))␈↓↓.␈↓ 



␈↓ ↓H␈↓8.  ␈↓αRecursive function definitions.␈↓


␈↓ ↓H␈↓        In␈α
such␈α
languages␈α
as␈α
FORTRAN␈α∞and␈α
 Algol,␈α
 computer␈α
 programs␈α
are␈α
 expressed␈α∞ in␈α
the
␈↓ ↓H␈↓main␈α⊃as␈α⊃sequences␈α⊃of␈α⊃assignment␈α⊃statements␈α⊃and␈α⊃conditional␈α⊃␈↓αgo␈α⊃to␈↓'s.␈α⊃ In␈α⊃LISP,␈α⊃programs␈α⊃are
␈↓ ↓H␈↓mainly expressed  in  the form of recursively defined functions.  We begin with an example.

␈↓ ↓H␈↓        The␈α∞ function␈α
  ␈↓↓alt x␈↓␈α∞  gives␈α
 a␈α∞ list␈α∞ whose␈α
 elements␈α∞ are␈α
alternate␈α∞elements␈α
of␈α∞the␈α∞list␈α
 ␈↓↓x␈↓
␈↓ ↓H␈↓beginning with the first.  Thus

␈↓ ↓H␈↓␈↓ ¬*␈↓↓alt ␈↓¬(A B C D E)␈↓↓ = ␈↓¬(A C E)␈↓↓␈↓, 

␈↓ ↓H␈↓␈↓ ¬#␈↓↓alt ␈↓¬(((A B) (C D))␈↓↓ = ␈↓¬((A B))␈↓↓␈↓, 

␈↓ ↓H␈↓␈↓ ¬y␈↓↓alt ␈↓¬(A)␈↓↓ = ␈↓¬(A)␈↓↓␈↓, 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ ¬x␈↓↓alt ␈↓¬NIL␈↓↓ = ␈↓¬NIL␈↓↓␈↓. 

␈↓ ↓H␈↓In LISP ␈↓↓alt␈↓ is defined by the equation

␈↓ ↓H␈↓␈↓ ∧*␈↓↓alt x ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ∨ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧x ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧x . alt ␈↓αdd␈↓↓␈α∧x␈↓. 

␈↓ ↓H␈↓In case you need a review of our precedence conventions, fully bracketed it looks like

␈↓ ↓H␈↓␈↓ βZ␈↓↓alt[x] ← ␈↓αif␈↓↓ [␈↓αn␈↓↓␈α∧[x] ∨ ␈↓αn␈↓↓␈α∧[␈↓αd␈↓↓␈α∧[x]]] ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ [␈↓αa␈↓↓␈α∧[x] . alt[␈↓αdd␈↓↓␈α∧[x]]]␈↓. 
␈↓ ↓H␈↓␈↓ ¬oCHAPTER I␈↓ *13


␈↓ ↓H␈↓        This␈αdefinition␈αuses␈αno␈αways␈αof␈αforming␈αexpressions␈αthat␈αwe␈αhaven't␈αintroduced␈αpreviously,
␈↓ ↓H␈↓but␈αit␈αuses␈αthe␈αfunction␈α␈↓↓alt␈↓␈αin␈αthe␈αright␈αhand␈αside␈αof␈αits␈αown␈αdefining␈αequation.␈α To␈αget␈αthe␈αvalue
␈↓ ↓H␈↓of␈α␈↓↓alt␈α
x␈↓␈αfor␈αsome␈α
particular␈αlist,␈αwe␈α
evaluate␈αthe␈αright␈α
hand␈αside␈αof␈α
the␈αdefinition␈αsubstituting␈α
that
␈↓ ↓H␈↓list␈α∩for␈α∪␈↓↓x␈↓␈α∩whenever␈α∪␈↓↓x␈↓␈α∩is␈α∪encountered␈α∩and␈α∩re-evaluating␈α∪the␈α∩right␈α∪hand␈α∩side␈α∪with␈α∩a␈α∪new␈α∩␈↓↓x␈↓
␈↓ ↓H␈↓whenever␈αa␈αform␈α␈↓↓alt␈αe␈↓␈α
is␈αencountered.␈α This␈αprocess␈αis␈α
 best␈α explained␈α by␈α using␈α it␈α
to␈αevaluate
␈↓ ↓H␈↓some expressions.

␈↓ ↓H␈↓        Consider␈α⊂evaluating␈α⊂␈↓↓alt ␈↓¬NIL␈↓↓␈↓.␈α⊂ We␈α⊂do␈α⊂it␈α⊂by␈α⊂evaluating␈α⊂the␈α⊂expression␈α⊂to␈α⊂the␈α⊂right␈α⊂of␈α⊂the
␈↓ ↓H␈↓␈↓α←␈↓  sign␈α∩remembering␈α∩that␈α⊃the␈α∩variable␈α∩ ␈↓↓x␈↓␈α⊃ has␈α∩the␈α∩value␈α⊃ ␈↓¬NIL␈↓.␈α∩ A␈α∩ conditional␈α∩expression␈α⊃ is
␈↓ ↓H␈↓evaluated␈αby␈αfirst␈αevaluating␈αthe␈αfirst␈αpropositional␈αterm␈α-␈αin␈αthis␈αcase␈α␈↓↓␈↓αn␈↓↓␈α∧x␈α∨␈α␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧x␈↓.␈αThis␈αexpression
␈↓ ↓H␈↓is␈αa␈αdisjunction␈αand␈αin␈α its␈αevaluation␈αwe␈αfirst␈αevaluate␈αthe␈αfirst␈αdisjunct,␈αnamely␈α ␈↓αn␈↓␈α∧␈↓↓x.␈↓␈αSince␈α ␈↓↓x␈↓␈α=
␈↓ ↓H␈↓␈↓¬NIL␈↓,␈α∂ ␈↓αn␈↓␈α∧␈↓↓x␈↓␈α∞ is␈α∂true,␈α∞the␈α∂disjunction␈α∞is␈α∂true,␈α∂and␈α∞the␈α∂value␈α∞of␈α∂ the␈α∞ conditional␈α∂ expression␈α∂ is␈α∞ the
␈↓ ↓H␈↓value␈αof␈αthe␈αterm␈αafter␈αthe␈αfirst␈αtrue␈αpropositiional␈αterm.␈αThe␈αterm␈αis␈α  ␈↓↓x,␈↓␈α and␈α its␈α value␈α is␈α␈↓¬NIL␈↓,
␈↓ ↓H␈↓so␈α
the␈α
value␈α
of␈α
 ␈↓↓alt[␈↓¬NIL␈↓↓]␈↓␈α
 is␈α
 ␈↓¬NIL␈↓␈α
 as␈αstated␈α
above.␈α
  Obeying␈α
the␈α
rules␈α
about␈α
the␈α
order␈αof␈α
evaluation
␈↓ ↓H␈↓of␈αterms␈αin␈α conditional␈α and␈αBoolean␈αexpressions␈αis␈αimportant␈αin␈αthis␈αcase␈αsince␈αif␈αwe␈αdidn't␈α
obey
␈↓ ↓H␈↓these␈α∞rules,␈α∞we␈α∞might␈α
find␈α∞ourselves␈α∞trying␈α∞to␈α
 evaluate␈α∞  ␈↓αn␈↓␈α∧␈↓αd␈↓␈α∧␈↓↓x␈↓␈α∞  or␈α∞␈↓↓alt[␈↓αdd␈↓↓␈α∧x]␈↓,␈α
and␈α∞since␈α∞ ␈↓↓x␈↓␈α∞is␈α
 ␈↓¬NIL␈↓,
␈↓ ↓H␈↓neither␈α
of␈α
these␈α
has␈α
a␈α
value.␈α An␈α
attempt␈α
to␈α
evaluate␈α
them␈α
in␈αLISP␈α
would␈α
give␈α
rise␈α
to␈α
an␈αerror
␈↓ ↓H␈↓return.

␈↓ ↓H␈↓        As␈αa␈α
second␈αexample,␈α
consider␈α  ␈↓↓alt ␈↓¬(A B)␈↓↓␈↓.␈α
  Since␈α neither␈α
␈↓αn␈↓␈α∧␈↓↓x␈↓␈αnor␈α
␈↓αn␈↓␈α∧␈↓αd␈↓␈α∧␈↓↓x␈↓␈α is␈α
true␈αin␈α
this␈αcase,
␈↓ ↓H␈↓the␈α⊃disjunction␈α⊃␈↓↓␈↓αn␈↓↓␈α∧x␈α⊃∨␈α⊃␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧x␈↓␈α⊃is␈α⊃ false␈α⊃ and␈α⊃ the␈α⊃ value␈α⊃ of␈α⊃ the␈α⊃ expression␈α⊃ is␈α⊃ the␈α∩  value␈α⊃  of
␈↓ ↓H␈↓␈↓↓␈↓αa␈↓↓␈α∧x . alt qdd x␈↓.␈α ␈↓αa␈↓␈α∧␈↓↓x␈↓␈αhas␈αthe␈αvalue␈α ␈↓¬A,␈α␈↓␈αand␈α␈↓αdd␈↓␈α∧␈↓↓x␈↓␈αhas␈αthe␈αvalue␈α␈↓¬NIL␈↓,␈αso␈αwe␈αmust␈αnow␈αevaluate␈α ␈↓↓alt ␈↓¬NIL␈↓↓␈↓,
␈↓ ↓H␈↓and␈α⊂we␈α⊂already␈α⊂know␈α⊂that␈α⊂this␈α⊂is␈α⊂␈↓¬NIL␈↓.␈α⊂ Therefore,␈α⊂ the␈α⊂ value␈α⊂ of␈α⊂␈↓↓alt ␈↓¬(A B)␈↓↓␈↓␈α⊂ is␈α⊂that␈α⊂of␈α⊂ ␈↓¬A . NIL␈↓
␈↓ ↓H␈↓which is  ␈↓¬(A)␈↓.

␈↓ ↓H␈↓        We can describe this  evaluation  in  a  less  wordy  way  by writing

␈↓ ↓H␈↓        ␈↓↓alt ␈↓¬(A B)␈↓↓   = ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧␈↓¬(A B)␈↓↓ ∨ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧␈↓¬(A B)␈↓↓ ␈↓αthen␈↓↓ ␈↓¬(A B)␈↓↓  ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧␈↓¬(A B)␈↓↓ . alt[␈↓αdd␈↓↓␈α∧␈↓¬(A B)␈↓↓]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓αif␈↓↓ ␈↓¬NIL␈↓↓ ∨ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧␈↓¬(A B)␈↓↓ ␈↓αthen␈↓↓ ␈↓¬(A B)␈↓↓  ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧␈↓¬(A B)␈↓↓ . alt[␈↓αdd␈↓↓␈α∧␈↓¬(A B)␈↓↓]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓αif␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αthen␈↓↓ ␈↓¬(A B)␈↓↓  ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧␈↓¬(A B)␈↓↓ . alt[␈↓αdd␈↓↓␈α∧␈↓¬(A B)␈↓↓]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓αa␈↓↓␈α∧␈↓¬(A B)␈↓↓ . alt[␈↓αdd␈↓↓␈α∧␈↓¬(A B)␈↓↓]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓¬A ␈↓↓. alt[␈↓¬NIL␈↓↓]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓¬A ␈↓↓. [␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧␈↓¬NIL␈↓↓ ∨ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧␈↓¬NIL␈↓↓ ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓  ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧␈↓¬NIL␈↓↓ . alt[␈↓αdd␈↓↓␈α∧␈↓¬NIL␈↓↓]]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓¬A ␈↓↓. [␈↓αif␈↓↓ ␈↓¬T␈↓↓ ∨ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧␈↓¬NIL␈↓↓ ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓  ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧␈↓¬NIL␈↓↓ . alt[␈↓αdd␈↓↓␈α∧␈↓¬NIL␈↓↓]]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓¬A ␈↓↓. [␈↓αif␈↓↓ ␈↓¬T␈↓↓ ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓  ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧␈↓¬NIL␈↓↓ . alt[␈↓αdd␈↓↓␈α∧␈↓¬NIL␈↓↓]]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓¬A ␈↓↓. [␈↓¬NIL␈↓↓]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓¬(A)␈↓↓␈↓.
␈↓ ↓H␈↓14␈↓ ¬oCHAPTER I␈↓ H


␈↓ ↓H␈↓        This␈α∂is␈α∂still␈α∂very␈α∂ long-winded,␈α∂ and␈α∞ now␈α∂ that␈α∂ the␈α∂ reader␈α∂understands␈α∂ the␈α∂ order␈α∞ of
␈↓ ↓H␈↓evaluation  of  conditional  and Boolean expressions, we can proceed more briefly to evaluate

␈↓ ↓H␈↓        ␈↓↓alt[␈↓¬(A B C D E)␈↓↓] = ␈↓¬A ␈↓↓. alt[␈↓¬(C D E)␈↓↓]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓¬A ␈↓↓. [␈↓¬C ␈↓↓. alt[␈↓¬(E)␈↓↓]]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓¬A ␈↓↓. [␈↓¬(C E)␈↓↓]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓¬(A C E)␈↓↓␈↓.

␈↓ ↓H␈↓        Here␈αare␈αthree␈αmore␈αexamples␈αof␈αrecursive␈αfunctions␈αand␈αtheir␈αapplication:␈αWe␈αdefine␈α ␈↓↓last␈↓
␈↓ ↓H␈↓by

␈↓ ↓H␈↓␈↓ ∧a␈↓↓last x ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧x ␈↓αthen␈↓↓ ␈↓αa␈↓↓␈α∧x ␈↓αelse␈↓↓ last ␈↓αd␈↓↓␈α∧x␈↓, 

␈↓ ↓H␈↓and we compute

␈↓ ↓H␈↓        ␈↓↓last ␈↓¬(A B C)␈↓↓ = ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧␈↓¬(A B C)␈↓↓ ␈↓αthen␈↓↓ ␈↓αa␈↓↓␈α∧␈↓¬(A B C)␈↓↓  ␈↓αelse␈↓↓ last ␈↓αd␈↓↓␈α∧␈↓¬(A B C)␈↓↓␈↓

␈↓ ↓H␈↓                        ␈↓↓= last ␈↓¬(B C)␈↓↓␈↓

␈↓ ↓H␈↓                        ␈↓↓= last ␈↓¬(C)␈↓↓␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓¬C␈↓↓␈↓.

␈↓ ↓H␈↓Clearly␈α
  ␈↓↓last␈↓␈α
  computes␈α the␈α
 last␈α
element␈α
of␈αa␈α
list.␈α
 ␈↓↓last ␈↓¬NIL␈↓↓␈↓␈α
is␈αundefined␈α
in␈α
the␈α
LISP␈αlanguage;
␈↓ ↓H␈↓the␈α⊂result␈α∂of␈α⊂trying␈α∂ to␈α⊂ compute␈α⊂ it␈α∂may␈α⊂be␈α∂an␈α⊂error␈α⊂message␈α∂or␈α⊂may␈α∂be␈α⊂some␈α⊂random␈α∂result
␈↓ ↓H␈↓depending on the implementation.

␈↓ ↓H␈↓        The function  ␈↓↓subst␈↓  is defined by

␈↓ ↓H␈↓␈↓ α∃␈↓↓subst[x, y, z] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεz ␈↓αthen␈↓↓ [␈↓αif␈↓↓ z ␈↓αeq␈↓↓ y ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ z] ␈↓αelse␈↓↓ subst[x,y,␈↓αa␈↓↓␈α∧z] . subst[x,y,␈↓αd␈↓↓␈α∧z]␈↓. 

␈↓ ↓H␈↓We have

␈↓ ↓H␈↓        ␈↓↓subst[␈↓¬(A.B), X, ((X.A).X)␈↓↓] =␈↓

␈↓ ↓H␈↓                        ␈↓↓= subst[␈↓¬(A.B), X, (X.A)␈↓↓] . subst[␈↓¬(A.B), X, X␈↓↓]␈↓

␈↓ ↓H␈↓                        ␈↓↓= [subst[␈↓¬(A.B), X, X␈↓↓] . subst[␈↓¬(A.B), X, A␈↓↓]] . ␈↓¬(A.B)␈↓↓␈↓

␈↓ ↓H␈↓                        ␈↓↓= [[␈↓¬(A.B)␈↓↓].␈↓¬A␈↓↓].␈↓¬(A.B)␈↓↓]␈↓

␈↓ ↓H␈↓                        ␈↓↓= ␈↓¬(((A.B).A).(A.B))␈↓↓␈↓.

␈↓ ↓H␈↓␈↓↓subst␈↓␈α⊃ computes␈α∩the␈α⊃result␈α∩of␈α⊃substituting␈α⊃the␈α∩S-expression␈α⊃  ␈↓↓x␈↓␈α∩  for␈α⊃the␈α⊃ atom␈α∩ ␈↓↓y␈↓␈α⊃ in␈α∩the␈α⊃S-
␈↓ ↓H␈↓expression  ␈↓↓z.␈↓  This operation is important in all kinds of symbolic computation.
␈↓ ↓H␈↓␈↓ ¬oCHAPTER I␈↓ *15


␈↓ ↓H␈↓        The␈α⊃function␈α⊃␈↓↓append[x,y]␈↓␈α⊃which␈α⊃gives␈α⊃the␈α∩ concatenation␈α⊃ of␈α⊃the␈α⊃lists␈α⊃␈↓↓x␈↓␈α⊃and␈α⊃␈↓↓y␈↓␈α∩is␈α⊃also
␈↓ ↓H␈↓important.␈α
 It␈α
is␈αalso␈α
denoted␈α
by␈α
the␈αinfixed␈α
expression␈α
  ␈↓↓x*y␈↓␈α
  since␈αit␈α
is␈α
associative.␈α
 We␈αhave␈α
the
␈↓ ↓H␈↓examples

␈↓ ↓H␈↓␈↓ ∧z␈↓↓␈↓¬(A B C)␈↓↓*␈↓¬(D E F)␈↓↓ = ␈↓¬(A B C D E F)␈↓↓,␈↓ 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ ¬␈↓↓␈↓¬NIL␈↓↓*␈↓¬(A B)␈↓↓ =␈↓¬(A B)␈↓↓ = ␈↓¬(A B)␈↓↓*␈↓¬NIL␈↓↓,␈↓ 

␈↓ ↓H␈↓and the formal definition

␈↓ ↓H␈↓␈↓ ∧X␈↓↓x*y ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ␈↓αthen␈↓↓ y ␈↓αelse␈↓↓ [␈↓αa␈↓↓␈α∧x].[[␈↓αd␈↓↓␈α∧x]*y]␈↓. 

␈↓ ↓H␈↓        The␈α
 Boolean␈α∞ operations␈α
can␈α∞also␈α
be␈α
used␈α∞in␈α
making␈α∞recursive␈α
definitions␈α∞ provided␈α
 we
␈↓ ↓H␈↓observe  the  order   of   evaluation   of constituents. First, we define a predicate  ␈↓↓equal␈↓  by

␈↓ ↓H␈↓␈↓ β
␈↓↓equal[x,y] ← x ␈↓αeq␈↓↓ y ∨ [¬␈↓αat␈↓↓␈αεx ∧ ¬␈↓αat␈↓↓␈αεy ∧  equal[␈↓αa␈↓↓␈α∧x,␈↓αa␈↓↓␈α∧y] ∧ equal[␈↓αd␈↓↓␈α∧x, ␈↓αd␈↓↓␈α∧y]]␈↓. 

␈↓ ↓H␈↓␈↓↓equal[x,y]␈↓␈αis␈αtrue␈αif␈αand␈αonly␈αif␈α  ␈↓↓x␈↓␈α  and␈α  ␈↓↓y␈↓␈α  are␈α the␈α same␈αS-expression,␈α and␈α the␈α use␈α of␈αthis
␈↓ ↓H␈↓predicate␈αmakes␈αup␈αfor␈αthe␈αfact␈αthat␈αthe␈αbasic␈αpredicate␈α ␈↓αeq␈↓␈α is␈αguaranteed␈α to␈α test␈α equality␈α only
␈↓ ↓H␈↓when  one  of the operands is known to be an atom.  We shall also use the infixes  ␈↓α=␈↓  and  ␈↓α≠␈↓.

␈↓ ↓H␈↓        Membership of an S-expression  ␈↓↓x␈↓  in a list  ␈↓↓y␈↓  is tested by

␈↓ ↓H␈↓␈↓ ∧	␈↓↓member[x, y] ← ¬␈↓αn␈↓↓␈α∧y ∧ [[x = ␈↓αa␈↓↓␈α∧y] ∨ member[x, ␈↓αd␈↓↓␈α∧y]]␈↓. 

␈↓ ↓H␈↓This relation is also denoted by ␈↓↓x ε y␈↓.  Here are some computations:

␈↓ ↓H␈↓        ␈↓↓member[␈↓¬B, ␈↓↓␈↓¬(A B)␈↓↓] = ¬␈↓αn␈↓↓␈α∧␈↓¬(A B)␈↓↓ ∧ [[␈↓¬B ␈↓↓= ␈↓αa␈↓↓␈α∧␈↓¬(A B)␈↓↓]  ∨ member[␈↓¬B, ␈↓↓␈↓αd␈↓↓␈α∧␈↓¬(A B)␈↓↓]]␈↓,

␈↓ ↓H␈↓                           ␈↓↓= member[␈↓¬B, ␈↓↓␈↓¬(B)␈↓↓]␈↓

␈↓ ↓H␈↓                           ␈↓↓= ␈↓¬T␈↓↓␈↓.

␈↓ ↓H␈↓        Sometimes␈α a␈α
 function␈α is␈αdefined␈α
with␈αthe␈α
help␈αof␈αauxiliary␈α
functions.␈α Thus,␈α
the␈αreverse
␈↓ ↓H␈↓of a list  ␈↓↓x␈↓ , (e.g.   ␈↓↓reverse[␈↓¬(A B C D)␈↓↓] = ␈↓¬(D C B A)␈↓↓␈↓), is given by

␈↓ ↓H␈↓␈↓ ¬4␈↓↓reverse[x] ← rev[x, ␈↓¬NIL␈↓↓]␈↓ 
λ
␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ ∧(␈↓↓rev[x, y] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ␈↓αthen␈↓↓ y ␈↓αelse␈↓↓ rev[␈↓αd␈↓↓␈α∧x, [␈↓αa␈↓↓␈α∧x].y]␈↓. 

␈↓ ↓H␈↓A computation is:

␈↓ ↓H␈↓        ␈↓↓reverse[␈↓¬(A B C)␈↓↓] = rev[␈↓¬(A B C)␈↓↓, ␈↓¬NIL␈↓↓]␈↓
␈↓ ↓H␈↓16␈↓ ¬oCHAPTER I␈↓ H


␈↓ ↓H␈↓                              ␈↓↓= rev[␈↓¬(B C), (A)␈↓↓]␈↓

␈↓ ↓H␈↓                              ␈↓↓= rev[␈↓¬(C), (B A)␈↓↓]␈↓

␈↓ ↓H␈↓                              ␈↓↓= rev[␈↓¬NIL␈↓↓, ␈↓¬(C B A)␈↓↓]␈↓

␈↓ ↓H␈↓                              ␈↓↓= ␈↓¬(C B A)␈↓↓␈↓.

␈↓ ↓H␈↓A more elaborate example of recursive definition is given by

␈↓ ↓H␈↓␈↓ ¬0␈↓↓flatten[x] ← flat[x, ␈↓¬NIL␈↓↓]␈↓ 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ βk␈↓↓flat[x, y] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ x.y  ␈↓αelse␈↓↓ flat[␈↓αa␈↓↓␈α∧x, flat[␈↓αd␈↓↓␈α∧x, y]]␈↓. 

␈↓ ↓H␈↓We have

␈↓ ↓H␈↓        ␈↓↓flatten[␈↓¬((A.B).C)␈↓↓] = flat[␈↓¬((A.B).C)␈↓↓, ␈↓¬NIL␈↓↓]␈↓

␈↓ ↓H␈↓                                ␈↓↓= flat[␈↓¬(A.B)␈↓↓, flat[␈↓¬C, ␈↓↓␈↓¬NIL␈↓↓]]␈↓

␈↓ ↓H␈↓                                ␈↓↓= flat[␈↓¬(A.B), (C)␈↓↓]␈↓

␈↓ ↓H␈↓                                ␈↓↓= flat[␈↓¬A, ␈↓↓flat[␈↓¬B, (C)␈↓↓]]␈↓

␈↓ ↓H␈↓                                ␈↓↓= flat[␈↓¬A, (B C)␈↓↓]␈↓

␈↓ ↓H␈↓                                ␈↓↓= ␈↓¬(A B C)␈↓↓␈↓.

␈↓ ↓H␈↓The␈α reader␈α will␈αsee␈αthat␈αthe␈αvalue␈αof␈α ␈↓↓flatten[x]␈↓␈α is␈αa␈αlist␈αof␈αthe␈αatoms␈α of␈α the␈α S-expression␈α  ␈↓↓x␈↓
␈↓ ↓H␈↓from   left   to   right.    Thus ␈↓↓flatten[␈↓¬((A B) A)␈↓↓] = ␈↓¬(A B NIL A NIL)␈↓↓␈↓.

␈↓ ↓H␈↓        Many␈α⊂ functions␈α⊂ can␈α∂be␈α⊂conveniently␈α⊂written␈α∂in␈α⊂more␈α⊂than␈α∂one␈α⊂way.␈α⊂ For␈α⊂example,␈α∂the
␈↓ ↓H␈↓function   ␈↓↓reverse␈↓   mentioned  above  can  be written without an auxiliary function as follows:

␈↓ ↓H␈↓␈↓ ∧␈↓↓reverse x ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ reverse ␈↓αd␈↓↓␈α∧x * <␈↓αa␈↓↓␈α∧x>␈↓, 

␈↓ ↓H␈↓but␈α∂the␈α∂earlier␈α∂ definition␈α∂ involves␈α∂less␈α∂computation,␈α∂because␈α∂*␈α∂takes␈α∂time␈α∂proportional␈α∂to␈α∂the
␈↓ ↓H␈↓length of its first argument.

␈↓ ↓H␈↓        The␈αuse␈α
of␈αconditional␈α
 expressions␈α for␈α recursive␈α
 function␈αdefinition␈α
 is␈α not␈α
 limited␈α to
␈↓ ↓H␈↓functions␈α∂ of␈α∞ S-expressions.␈α∂  For␈α∞example,␈α∂the␈α∞factorial␈α∂function␈α∞and␈α∂the␈α∂Euclidean␈α∞algorithm
␈↓ ↓H␈↓for  the greatest common divisor are expressed as follows:

␈↓ ↓H␈↓␈↓ ¬α␈↓↓n! ← ␈↓αif␈↓↓ n=0 ␈↓αthen␈↓↓ 1 ␈↓αelse␈↓↓ n(n-1)!␈↓ 

␈↓ ↓H␈↓and
␈↓ ↓H␈↓␈↓ ¬oCHAPTER I␈↓ *17


␈↓ ↓H␈↓␈↓ αV␈↓↓gcd(m, n) ← ␈↓αif␈↓↓ m>n ␈↓αthen␈↓↓ gcd(n, m) ␈↓αelse␈↓↓ ␈↓αif␈↓↓ m=0 ␈↓αthen␈↓↓ n ␈↓αelse␈↓↓ gcd(n mod m, m)␈↓ 

␈↓ ↓H␈↓where␈α ␈↓↓n␈αmod␈αm␈↓␈α denotes␈αthe␈αremainder␈αwhen␈α ␈↓↓n␈↓␈α is␈αdivided␈αby␈α ␈↓↓m␈↓␈α  and␈αmay␈αitself␈αbe␈αexpressed
␈↓ ↓H␈↓recursively by

␈↓ ↓H␈↓␈↓ ∧*␈↓↓n mod m ← ␈↓αif␈↓↓ n<m ␈↓αthen␈↓↓ n ␈↓αelse␈↓↓ (n-m) mod m␈↓. 

␈↓ ↓H␈↓        The␈α
internal␈α
form␈α
of␈α
function␈αdefinitions␈α
depends␈α
on␈α
the␈α
implementation.␈α
 Stanford␈αLISP
␈↓ ↓H␈↓and UCI LISP for the PDP-10 computer use the form

␈↓ ↓H␈↓                (DE <function name> <list of variables> <right hand side>).

␈↓ ↓H␈↓In these LISPs, the above definition of ␈↓↓subst␈↓ is

␈↓ ↓H␈↓                ␈↓¬(DE SUBST (X Y Z) ␈↓
␈↓ ↓H␈↓                  ␈↓¬(COND ((ATOM Z) (COND ((EQ Z X) Y) (T Z)))␈↓
␈↓ ↓H␈↓                        ␈↓¬(T (CONS (SUBST X Y (CAR Z)) (SUBST X Y (CDR Z))))))␈↓,

␈↓ ↓H␈↓and the definition of ␈↓↓alt␈↓ is

␈↓ ↓H␈↓                ␈↓¬(DE ALT (X) ␈↓
␈↓ ↓H␈↓                  ␈↓¬(COND ((OR (NULL X) (NULL (CDR X))) X)␈↓
␈↓ ↓H␈↓                        ␈↓¬(T (CONS (CAR X) (ALT (CDDR X))))))␈↓.

␈↓ ↓H␈↓MACLISP␈α⊂uses␈α⊂␈↓¬DEFUN␈↓␈α⊂instead␈α⊂of␈α⊂␈↓¬DE␈↓.␈α∂ Yet␈α⊂another␈α⊂notation␈α⊂for␈α⊂function␈α⊂definition␈α⊂called␈α∂the
␈↓ ↓H␈↓␈↓¬DEFPROP ␈↓notation will be explained after λ-expressions have been introduced.


␈↓ ↓H␈↓α␈↓ ε
Exercises

␈↓ ↓H␈↓        1. Consider the function  ␈↓↓drop␈↓  defined by

␈↓ ↓H␈↓␈↓ ∧ ␈↓↓drop[x] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ <␈↓αa␈↓↓␈α∧x> . drop[␈↓αd␈↓↓␈α∧x]␈↓. 

␈↓ ↓H␈↓Compute␈α∂(by␈α∞hand)␈α∂ ␈↓↓drop[␈↓¬(A␈α∂B␈α∞C)␈↓↓]␈↓.␈α∂ What␈α∂does␈α∞ ␈↓↓drop␈↓␈α∂ do␈α∞ to␈α∂ lists␈α∂ in␈α∞general?␈α∂ Write␈α∂␈↓↓drop␈↓␈α∞in
␈↓ ↓H␈↓internal notation using ␈↓¬DE. ␈↓

␈↓ ↓H␈↓        2. What does the function

␈↓ ↓H␈↓␈↓ ∧≥␈↓↓r2[x] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ reverse[␈↓αa␈↓↓␈α∧x] . r2[␈↓αd␈↓↓␈α∧x]␈↓ 

␈↓ ↓H␈↓do to lists of lists?  How about

␈↓ ↓H␈↓␈↓ ∧L␈↓↓r3[x] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ reverse[r4[x]]␈↓ 

␈↓ ↓H␈↓␈↓ ∧5␈↓↓r4[x] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ r3[␈↓αa␈↓↓␈α∧x] . r4[␈↓αd␈↓↓␈α∧x]␈↓? 

␈↓ ↓H␈↓        3. Compare
␈↓ ↓H␈↓18␈↓ ¬oCHAPTER I␈↓ H


␈↓ ↓H␈↓␈↓ ∧≤␈↓↓r3'[x] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ r3'[␈↓αd␈↓↓␈α∧x] * <r3'[␈↓αa␈↓↓␈α∧x]>␈↓ 

␈↓ ↓H␈↓with the function  ␈↓↓r3␈↓  of the preceding example.

␈↓ ↓H␈↓        4. Consider  ␈↓↓r5␈↓  defined by

␈↓ ↓H␈↓␈↓ β*␈↓↓r5[x] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ∨ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧x ␈↓αthen␈↓↓ x  ␈↓αelse␈↓↓ [␈↓αa␈↓↓␈α∧r5[␈↓αd␈↓↓␈α∧x]] . r5[␈↓αa␈↓↓␈α∧x . r5[␈↓αd␈↓↓␈α∧r5[␈↓αd␈↓↓␈α∧x]]]␈↓. 

␈↓ ↓H␈↓Compute␈α∩ ␈↓↓r5[␈↓¬(A␈α∩B␈α∩C␈α∩D)␈↓↓]␈↓.␈α∩ What␈α∩does␈α∩␈↓↓r5␈↓␈α∩ do?␈α∩  Needless␈α∩ to␈α∩say,␈α∩this␈α∩is␈α∩not␈α∩a␈α∩good␈α∩way␈α⊃of
␈↓ ↓H␈↓computing this function even though it involves no auxiliary functions.



␈↓ ↓H␈↓9.  ␈↓αLambda expressions and functions with functions as arguments.␈↓


␈↓ ↓H␈↓        It␈α⊂is␈α⊂common␈α⊂to␈α⊂use␈α⊂phrases␈α⊂like␈α⊂"the␈α⊂function␈α⊂ ␈↓↓2x+y␈↓".␈α⊂  This␈α⊂is␈α⊂ not␈α⊂a␈α⊂precise␈α⊂notation
␈↓ ↓H␈↓because␈α
we␈α
cannot␈αsay␈α
 ␈↓↓2x+y(3,␈α
4)␈↓␈α
 and␈αknow␈α
whether␈α
the␈α
desired␈α result␈α
 is␈α
  2␈↓#
.␈↓#3+4␈α
  or␈α  2␈↓#
.␈↓#4+3
␈↓ ↓H␈↓regarding␈α
 the␈α
expression␈α
 as␈α
a␈α
function␈α
of␈α
two␈α
variables.␈α
 Worse␈α
yet,␈α
we␈α
might␈α
have␈α
meant␈α
a␈α
one-
␈↓ ↓H␈↓variable function of  ␈↓↓x␈↓  wherein  ␈↓↓y␈↓   is  regarded  as  a parameter.

␈↓ ↓H␈↓        The␈α∞problem␈α
 of␈α∞ giving␈α
 names␈α∞ to␈α
 functions␈α∞ is␈α
 solved␈α∞ by␈α
Church's␈α∞  λ-notation.␈α
   In
␈↓ ↓H␈↓the␈α∞ above␈α∞ example,␈α∞ we␈α∞ would␈α∞ write␈α∞␈↓↓λx␈α∞y:␈α∞2x+y␈↓␈α∞ to␈α∞denote␈α∞ the␈α∞ function␈α∞ of␈α∂ two␈α∞ variables
␈↓ ↓H␈↓with␈α⊂ first␈α⊂argument␈α∂  ␈↓↓x␈↓␈α⊂  and␈α⊂ second␈α⊂ argument␈α∂  ␈↓↓y␈↓␈α⊂ whose␈α⊂value␈α∂is␈α⊂given␈α⊂by␈α⊂the␈α∂expression
␈↓ ↓H␈↓␈↓↓2x+y␈↓.  Thus,

␈↓ ↓H␈↓␈↓ ¬⊗␈↓↓[λx y: 2x+y][3, 4] = 10.     ␈↓ 

␈↓ ↓H␈↓Likewise,

␈↓ ↓H␈↓␈↓ ¬⊗␈↓↓[λy x: 2x+y][3, 4] = 11.     ␈↓ 

␈↓ ↓H␈↓Like␈αvariables␈αof␈αintegration␈αand␈αthe␈αbound␈αvariables␈αof␈αquantifiers␈αin␈αlogic,␈α
variables␈αfollowing
␈↓ ↓H␈↓λ␈αare␈α bound␈α or␈αdummy␈αand␈αthe␈αexpression␈αas␈αa␈αwhole␈αmay␈αbe␈αreplaced␈αby␈αany␈αothers␈αprovided
␈↓ ↓H␈↓the␈αreplacement␈αis␈αdone␈αconsistently␈αand␈αdoes␈αnot␈αmake␈α any␈α variable␈α bound␈α by␈α λ␈α the␈αsame␈α
as
␈↓ ↓H␈↓a␈α∪free␈α∪variable␈α∪in␈α∪the␈α∀expression.␈α∪ Thus␈α∪  ␈↓↓λx y: 2x+y␈↓␈α∪  represents␈α∪ the␈α∪ same␈α∀  function␈α∪  as
␈↓ ↓H␈↓␈↓↓λy x: 2y+x␈↓␈α
or␈α
␈↓↓λu v: 2u+v␈↓␈α
,␈α
but␈α
in␈α
the␈α∞function␈α
of␈α
one␈α
argument␈α
␈↓↓λx: 2x+y␈↓␈α
,␈α
we␈α
cannot␈α∞replace␈α
the
␈↓ ↓H␈↓variable  ␈↓↓x␈↓  by ␈↓↓y1␈↓ , though we could replace it by  ␈↓↓u.␈↓

␈↓ ↓H␈↓        λ-notation␈α∃plays␈α∃two␈α∃important␈α∃ roles␈α∃ in␈α∃ LISP.␈α∃  First,␈α∃ it␈α∃allows␈α∃us␈α∃to␈α⊗rewrite␈α∃an
␈↓ ↓H␈↓expression␈αcontaining␈αtwo␈αor␈αmore␈αoccurrences␈αof␈αthe␈αsame␈αsub-expression␈αin␈αsuch␈αa␈αway␈αthat␈αthe
␈↓ ↓H␈↓expression␈α∞ occurs␈α∞only␈α∞once.␈α∞Thus␈α∞  ␈↓↓(2x+1)␈↓∧4␈↓↓+3(2x+1)␈↓∧3␈↓␈α∞ can␈α∞be␈α∞written␈α∞␈↓↓[λw: w␈↓∧4␈↓↓+3w␈↓∧3␈↓↓][2x+1]␈↓.␈α
This
␈↓ ↓H␈↓can␈α
save␈α
considerable␈α
computation,␈α
and␈α
corresponds␈αto␈α
the␈α
practice␈α
in␈α
ordinary␈α
programming␈αof
␈↓ ↓H␈↓assigning␈α∀to␈α∪a␈α∀variable␈α∪the␈α∀value␈α∪of␈α∀a␈α∪sub-expression␈α∀that␈α∪occurs␈α∀more␈α∪than␈α∀once␈α∀ in␈α∪an
␈↓ ↓H␈↓expression  and  then  writing  the  expression  in  terms of the variable.

␈↓ ↓H␈↓        The␈α
second␈α
use␈α
of␈α
λ-expressions␈α
is␈α
in␈α
 using␈α
 functions␈α
 that␈α
take␈α
functions␈α
as␈αarguments.
␈↓ ↓H␈↓␈↓ ¬oCHAPTER I␈↓ *19


␈↓ ↓H␈↓Suppose␈αwe␈αwant␈α
to␈αform␈αa␈αnew␈α
list␈αfrom␈αan␈αold␈α
one␈αby␈αapplying␈αa␈α
function␈α ␈↓↓f␈↓␈α to␈α
each␈αelement
␈↓ ↓H␈↓of  the  list.  This can be done using the function  ␈↓↓mapcar␈↓  defined by

␈↓ ↓H␈↓␈↓ βV␈↓↓mapcar[x, f] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ f[␈↓αa␈↓↓␈α∧x] . mapcar[␈↓αd␈↓↓␈α∧x, f]␈↓. 

␈↓ ↓H␈↓Such␈α∂a␈α∂function␈α∂is␈α∂called␈α∂a␈α∂␈↓↓functional.␈↓␈α∂ It␈α∂can␈α∂be␈α∂viewed␈α∂as␈α∂mapping␈α∂a␈α∂function␈α∂into␈α∞another
␈↓ ↓H␈↓function.␈α Suppose␈αthe␈αoperation␈αwe␈αwant␈αto␈αperform␈αis␈αsquaring,␈αand␈αwe␈αwant␈α to␈αapply␈αit␈αto␈αthe
␈↓ ↓H␈↓list  ␈↓¬(1 2 3 4 5 6 7)␈↓.  We have

␈↓ ↓H␈↓␈↓ βi␈↓↓mapcar[␈↓¬(1 2 3 4 5 6 7)␈↓↓, λx: x␈↓∧2␈↓↓] = ␈↓¬(1 4 9 16 25 36 49)␈↓↓␈↓. 

␈↓ ↓H␈↓        A␈α⊃more␈α⊃generally␈α⊃useful␈α⊃operation␈α⊃than␈α⊃ ␈↓↓mapcar␈↓␈α⊃is␈α⊃␈↓↓maplist␈↓␈α⊃in␈α⊃ which␈α⊃ the␈α⊃ function␈α⊂is
␈↓ ↓H␈↓applied to the successive sublists of the list rather than to the elements.  ␈↓↓maplist␈↓  is defined by

␈↓ ↓H␈↓␈↓ β\␈↓↓maplist[x, f] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ f[x] . maplist[␈↓αd␈↓↓␈α∧x, f]␈↓. 

␈↓ ↓H␈↓        As␈α
 an␈α
 application␈α
 of␈α
 ␈↓↓maplist␈↓␈α
and␈αfunctional␈α
arguments,␈α
we␈α
shall␈α
define␈α
a␈α
function␈α for
␈↓ ↓H␈↓differentiating␈α algebraic␈α
 expressions␈αinvolving␈α
sums␈αand␈α
products.␈α The␈α
expressions␈αare␈αbuilt␈α
up
␈↓ ↓H␈↓from atoms denoting variables and integer constants according to the syntax

␈↓ ↓H␈↓        <expression> ::= <variable> | <integer> | (PLUS <explist>) | (TIMES <explist>)

␈↓ ↓H␈↓        <explist>    ::= <expression> | <expression><explist>

␈↓ ↓H␈↓Here,␈α⊂ ␈↓¬PLUS␈↓␈α⊂ followed␈α∂by␈α⊂a␈α⊂list␈α∂of␈α⊂arguments␈α⊂denotes␈α∂the␈α⊂sum␈α⊂of␈α∂these␈α⊂arguments␈α⊂and␈α∂ ␈↓¬TIMES␈↓
␈↓ ↓H␈↓followed␈α∂by␈α⊂a␈α∂list␈α⊂of␈α∂arguments␈α⊂ denotes␈α∂ their␈α⊂product.␈α∂  The␈α⊂ function␈α∂  ␈↓↓diff[e, v]␈↓␈α⊂ gives␈α∂the
␈↓ ↓H␈↓partial derivative of the expression  ␈↓↓e␈↓  with respect to the variable  ␈↓↓v.␈↓ We have

␈↓ ↓H␈↓        ␈↓↓diff[e, v] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεe ␈↓αthen␈↓↓ [␈↓αif␈↓↓ e ␈↓αeq␈↓↓ v ␈↓αthen␈↓↓ 1 ␈↓αelse␈↓↓ 0]␈↓
␈↓ ↓H␈↓                       ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e ␈↓αeq␈↓↓ ␈↓¬PLUS ␈↓↓␈↓αthen␈↓↓  ␈↓¬PLUS ␈↓↓. mapcar[␈↓αd␈↓↓␈α∧e, λx: diff[x, v] ]␈↓
␈↓ ↓H␈↓                       ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e ␈↓αeq␈↓↓ ␈↓¬TIMES ␈↓↓␈↓αthen␈↓↓  ␈↓¬PLUS ␈↓↓. maplist[␈↓αd␈↓↓␈α∧e,␈↓
␈↓ ↓H␈↓                                ␈↓↓λx: ␈↓¬TIMES ␈↓↓. maplist[␈↓αd␈↓↓␈α∧e, λy: ␈↓αif␈↓↓ x ␈↓αeq␈↓↓ y ␈↓αthen␈↓↓ diff[␈↓αa␈↓↓␈α∧y, v] ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧y]]␈↓.

␈↓ ↓H␈↓The  term  that  describes  the  rule  for  differentiating  products corresponds to the rule

␈↓ ↓H␈↓␈↓ ∧A␈↓↓∂/∂v[␈↓	P␈↓↓␈↓βi␈↓↓e␈↓βi␈↓↓] = ␈↓	S␈↓↓␈↓βi␈↓	 P␈↓βj [␈↓αif␈↓β i=j ␈↓αthen␈↓β ∂ej/∂v ␈↓αelse␈↓β ej] .␈↓ 

␈↓ ↓H␈↓and␈α  ␈↓↓maplist␈↓␈α  has␈α to␈αbe␈α
used␈αrather␈αthan␈α ␈↓↓mapcar␈↓␈α since␈α
whether␈αto␈αdifferentiate␈αin␈αforming␈α
the
␈↓ ↓H␈↓product␈α
is␈α
determined␈α
by␈α
equality␈α
of␈α
the␈α
indices␈α  ␈↓↓i␈↓␈α
  and␈α
  ␈↓↓j␈↓␈α
  rather␈α
 than␈α
equality␈α
of␈α
the␈αterms␈α
 ␈↓↓e␈↓βi␈↓
␈↓ ↓H␈↓and ␈↓↓e␈↓βj␈↓.

␈↓ ↓H␈↓        Two␈αadditional␈α
useful␈αfunctions␈α
with␈αfunctions␈α
as␈αarguments␈α
are␈αthe␈α
predicates␈α ␈↓↓andlis␈↓␈α
 and
␈↓ ↓H␈↓␈↓↓orlis␈↓  defined by the equations

␈↓ ↓H␈↓␈↓ ∧)␈↓↓andlis[u, p] ← ␈↓αn␈↓↓␈α∧u ∨ [p[␈↓αa␈↓↓␈α∧u] ∧ andlis[␈↓αd␈↓↓␈α∧u, p]]␈↓ 

␈↓ ↓H␈↓and
␈↓ ↓H␈↓20␈↓ ¬oCHAPTER I␈↓ H


␈↓ ↓H␈↓␈↓ ∧4␈↓↓orlis[u, p] ← ¬␈↓αn␈↓↓␈α∧u ∧ [p[␈↓αa␈↓↓␈α∧u] ∨ orlis[␈↓αd␈↓↓␈α∧u, p]]␈↓. 

␈↓ ↓H␈↓        The internal form for a λ-expression is

␈↓ ↓H␈↓                (LAMBDA <list of variables> <expression to be evaluated>).

␈↓ ↓H␈↓Thus␈α
␈↓↓λx:␈αdiff[x,v]␈↓␈α
is␈α
written␈α␈↓¬(LAMBDA␈α
(X)␈α
(DIFF␈αX␈α
V))␈↓.␈α
 When␈αa␈α
function␈α
specified␈αwith␈α
λ␈αis␈α
written
␈↓ ↓H␈↓as␈αan␈αargument␈αof␈αa␈α
function␈αtaking␈αa␈αfunctional␈αargument,␈α
then␈αthe␈αλ-expression␈αis␈αmarked␈α
with
␈↓ ↓H␈↓the identifier ␈↓¬FUNCTION. ␈↓ Thus the above definition of ␈↓↓diff␈↓ translates to

␈↓ ↓H␈↓        ␈↓¬(DE DIFF (E V) (COND␈↓
␈↓ ↓H␈↓          ␈↓¬((ATOM E) (COND ((EQ E V) 1) (T 0)))␈↓
␈↓ ↓H␈↓          ␈↓¬((EQ (CAR E) (QUOTE PLUS))␈↓
␈↓ ↓H␈↓            ␈↓¬(CONS (QUOTE PLUS)␈↓
␈↓ ↓H␈↓              ␈↓¬(MAPCAR (CDR E) (FUNCTION (LAMBDA (X) (DIFF X V))))))␈↓
␈↓ ↓H␈↓          ␈↓¬((EQ (CAR E) (QUOTE TIMES))␈↓
␈↓ ↓H␈↓            ␈↓¬(CONS (QUOTE PLUS)␈↓
␈↓ ↓H␈↓              ␈↓¬(MAPLIST (CDR E)␈↓
␈↓ ↓H␈↓                ␈↓¬(FUNCTION (LAMBDA (X) ␈↓
␈↓ ↓H␈↓                  ␈↓¬(CONS (QUOTE TIMES)␈↓
␈↓ ↓H␈↓                    ␈↓¬(MAPLIST (CDR E)␈↓
␈↓ ↓H␈↓                      ␈↓¬(FUNCTION (LAMBDA (Y)␈↓
␈↓ ↓H␈↓                        ␈↓¬(COND ((EQ X Y) (DIFF (CAR Y) V)) (T (CAR Y))))))))))))))␈↓.

␈↓ ↓H␈↓        Another␈α∞way␈α∞of␈α∞writing␈α∞function␈α∞definitions␈α∂in␈α∞internal␈α∞notation␈α∞uses␈α∞␈↓¬LAMBDA␈α∞␈↓to␈α∂make␈α∞a
␈↓ ↓H␈↓function of the right side of a definition.  It is like writing ␈↓↓subst␈↓ and ␈↓↓alt␈↓ as

␈↓ ↓H␈↓␈↓ α~␈↓↓subst = λx y z:[␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεz ␈↓αthen␈↓↓ [␈↓αif␈↓↓ z ␈↓αeq␈↓↓ y ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ z]  ␈↓αelse␈↓↓ subst[x,y,␈↓αa␈↓↓␈α∧z] . subst[x,y,␈↓αd␈↓↓␈α∧z]]␈↓ 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ ∧_␈↓↓alt = λx.[␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ∨ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧x ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧x . alt ␈↓αdd␈↓↓␈α∧x]␈↓. 

␈↓ ↓H␈↓The definitions of ␈↓↓subst␈↓ and ␈↓↓alt␈↓ take the forms

␈↓ ↓H␈↓        ␈↓¬(DEFPROP SUBST␈↓
␈↓ ↓H␈↓          ␈↓¬(LAMBDA (X Y Z) (COND ((ATOM Z) (COND ((EQ Z X) Y) (T Z)))␈↓
␈↓ ↓H␈↓                ␈↓¬(T (CONS (SUBST X Y (CAR Z)) (SUBST X Y (CDR Z)))))) EXPR)␈↓,

␈↓ ↓H␈↓and

␈↓ ↓H␈↓        ␈↓¬(DEFPROP ALT␈↓
␈↓ ↓H␈↓          ␈↓¬(LAMBDA (X) (COND ((OR (NULL X) (NULL (CDR X))) X)␈↓
␈↓ ↓H␈↓                ␈↓¬(T (CONS (CAR X) (ALT (CDDR X)))))) EXPR)␈↓.

␈↓ ↓H␈↓        The␈αgeneral␈αform␈α
is␈α(DEFPROP␈α<function␈αname>␈α
<defining␈αλ-expression>␈αEXPR)␈α
and␈αis
␈↓ ↓H␈↓often␈α
used␈α
by␈α∞programs␈α
that␈α
output␈α∞LISP.␈α
 It␈α
is␈α
a␈α∞special␈α
case␈α
of␈α∞an␈α
operation␈α
on␈α∞property␈α
lists
␈↓ ↓H␈↓␈↓ ¬oCHAPTER I␈↓ *21


␈↓ ↓H␈↓that␈α
puts␈αthe␈α
λ-expression␈α
on␈αthe␈α
property␈αof␈α
the␈α
name␈α␈↓¬ALT␈↓.␈α
 ␈↓¬EXPR␈↓␈αsays␈α
that␈α
the␈αitem␈α
is␈α
a␈αLISP
␈↓ ↓H␈↓function␈α∪defined␈α∪by␈α∩an␈α∪S-expression.␈α∪ (Rather␈α∩than␈α∪by␈α∪a␈α∩machine␈α∪language␈α∪subroutine,␈α∩for
␈↓ ↓H␈↓instance).


␈↓ ↓H␈↓α␈↓ ε
Exercises

␈↓ ↓H␈↓        1.␈αCompute␈α ␈↓↓diff[␈↓¬(TIMES␈αX␈α
(PLUS␈αY␈α1)␈α3),␈α
X␈↓↓]␈↓␈α using␈α the␈α above␈α
definition␈α of␈α ␈↓↓diff.␈↓␈α Now␈α
do
␈↓ ↓H␈↓you see why algebraic simplification is important?

␈↓ ↓H␈↓        2. Compute  ␈↓↓orlis[␈↓¬((A B) (C D) E)␈↓↓, ␈↓αat␈↓↓]␈↓.



␈↓ ↓H␈↓10.  ␈↓αLabel.␈↓


␈↓ ↓H␈↓        The␈α∀λ␈α∪mechanism␈α∀is␈α∀ not␈α∪ adequate␈α∀ for␈α∀ providing␈α∪ names␈α∀ for␈α∀recursive␈α∪ functions,
␈↓ ↓H␈↓because␈α in␈αthis␈αcase␈α
there␈αhas␈αto␈αbe␈αa␈α
way␈αof␈αreferring␈αto␈α
the␈αfunction␈αname␈αwithin␈αthe␈α
 function.
␈↓ ↓H␈↓Therefore,␈α we␈α
use␈α the␈α
notation␈α ␈↓↓label[f,␈α
e]␈↓␈α to␈α
denote␈αthe␈α
expression␈α ␈↓↓e␈↓␈α
 but␈αwhere␈αoccurrences␈α
of
␈↓ ↓H␈↓␈↓↓f␈↓␈α⊂ within␈α⊂ ␈↓↓e␈↓␈α⊂ refer␈α⊂ to␈α⊂ the␈α⊂ whole␈α⊂ expression.␈α⊂ For␈α⊂example,␈α⊂ suppose␈α⊂we␈α⊂wished␈α⊂to␈α⊃define␈α⊂a
␈↓ ↓H␈↓function␈αthat␈αtakes␈α
alternate␈αelements␈αof␈α
each␈αelement␈αof␈αa␈α
list␈αand␈αmakes␈α
a␈αlist␈αof␈α
these.␈α  Thus,
␈↓ ↓H␈↓we want

␈↓ ↓H␈↓␈↓ βy␈↓↓glub[␈↓¬((A B C) (A B C D) (X Y Z))␈↓↓] = ␈↓¬((A C) (A C) (X Z))␈↓↓␈↓. 

␈↓ ↓H␈↓We can make the definition

␈↓ ↓H␈↓␈↓ αl␈↓↓glub[x] ← mapcar[x, label[alt, λx: ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ∨ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧x ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧x . alt[␈↓αdd␈↓↓␈α∧x]]]␈↓. 

␈↓ ↓H␈↓        The␈α∂internal␈α⊂form␈α∂of␈α⊂␈↓↓label[<name>,<function␈α∂expression>]␈↓␈α⊂is␈α∂(LABEL␈α⊂<name>␈α∂<function
␈↓ ↓H␈↓expression>), so that the internal form of the definition of ␈↓↓glub␈↓ is

␈↓ ↓H␈↓        ␈↓¬(DE GLUB (X)␈↓
␈↓ ↓H␈↓          ␈↓¬(MAPCAR X␈↓
␈↓ ↓H␈↓            ␈↓¬(LABEL ALT (LAMBDA (X)␈↓
␈↓ ↓H␈↓              ␈↓¬(COND (OR (NULL X) (NULL (CDR X))) X) (T (CONS (CAR X) (ALT (CDDR X))))))))␈↓.

␈↓ ↓H␈↓        The␈α∩identifier␈α∩ ␈↓↓alt␈↓␈α∩ in␈α∩the␈α∩above␈α∩example␈α∩is␈α∩bound␈α∩by␈α∩  ␈↓↓label␈↓␈α∩ and␈α∩is␈α∩ local␈α∩ to␈α∩ that
␈↓ ↓H␈↓expression,␈α and␈α this␈αis␈αthe␈αgeneral␈αrule.␈α The␈αlabel␈α construction␈αis␈αnot␈αoften␈αused␈αin␈αLISP␈αsince
␈↓ ↓H␈↓it␈αis␈αmore␈αusual␈αto␈α give␈αfunctions␈αglobal␈α
definitions.␈αD.␈αM.␈αR.␈αPark␈αpointed␈αout␈αthat␈αif␈α
we␈αallow
␈↓ ↓H␈↓variables␈α∞to␈α∞represent␈α
functions␈α∞and␈α∞use␈α∞a␈α
 suitable␈α∞  λ␈α∞construction,␈α∞the␈α
use␈α∞of␈α∞ label␈α∞ could␈α
be
␈↓ ↓H␈↓avoided.
␈↓ ↓H␈↓22␈↓ ¬oCHAPTER I␈↓ H


␈↓ ↓H␈↓11.  ␈↓αNumerical computation.␈↓


␈↓ ↓H␈↓        Numerical␈α
calculation␈α
and␈α
symbolic␈α
calculation␈α
must␈α
often␈α
be␈α
combined,␈α
so␈α
LISP␈αprovides
␈↓ ↓H␈↓for numerical computation also.

␈↓ ↓H␈↓        In␈αthe␈α
first␈αplace,␈α
we␈αneed␈α
to␈αinclude␈α
numbers␈αas␈α
parts␈αof␈α
symbolic␈αexpressions.␈α
 LISP␈αhas
␈↓ ↓H␈↓both␈α
integer␈α∞and␈α
floating␈α
point␈α∞numbers␈α
which␈α
are␈α∞regarded␈α
as␈α
atoms.␈α∞ These␈α
numbers␈α∞may␈α
be
␈↓ ↓H␈↓included as atoms in writing S-expressions.  Thus we can have the lists:

␈↓ ↓H␈↓                ␈↓¬(1 3 5)␈↓
␈↓ ↓H␈↓                ␈↓¬(3.5 6.1 -7.2E9)␈↓
␈↓ ↓H␈↓                ␈↓¬(PLUS X 1.3)␈↓.

␈↓ ↓H␈↓The␈αfirst␈αis␈αa␈αlist␈αof␈α
integers,␈αthe␈αsecond␈αa␈αlist␈αof␈α
floating␈αpoint␈αnumbers,␈αand␈αthe␈αthird␈αa␈α
symbolic
␈↓ ↓H␈↓list␈α∞containing␈α
both␈α∞numberical␈α
and␈α∞non-numerical␈α
atoms.␈α∞ Integers␈α
are␈α∞written␈α∞without␈α
decimal
␈↓ ↓H␈↓points␈α∞which␈α∞are␈α∂used␈α∞to␈α∞signal␈α∂floating␈α∞point␈α∞numbers.␈α∞ As␈α∂in␈α∞Fortran,␈α∞the␈α∂letter␈α∞E␈α∞is␈α∂used␈α∞to
␈↓ ↓H␈↓signal␈αthe␈αexponent␈αof␈αa␈αfloating␈αpoint␈αnumber␈αwhich␈αis␈αa␈αsigned␈αinteger.␈α The␈αsizes␈α
of␈αnumbers
␈↓ ↓H␈↓admitted␈α
depends␈α
on␈α
the␈α
implementation.␈α
 When␈α
a␈α
dotted␈α
pair,␈α
say␈α
␈↓¬(1␈α
.␈α
2)␈↓␈α
is␈α
wanted,␈α∞the␈α
spaces
␈↓ ↓H␈↓around␈α
the␈α
dot␈αdistinguish␈α
it␈α
from␈αthe␈α
list␈α
␈↓¬(1.2)␈↓␈αwhose␈α
sole␈α
element␈αis␈α
the␈α
floating␈α
point␈αnumber
␈↓ ↓H␈↓1.2.

␈↓ ↓H␈↓        In␈α
publication␈αlanguage␈α
we␈α
will␈αuse␈α
ordinary␈α
mathematical␈αnotation␈α
for␈αnumerical␈α
functions.
␈↓ ↓H␈↓For␈αexponentiation␈αwe␈αwill␈αuse␈αthe␈αusual␈αsuperscript␈αnotation␈α␈↓↓x␈↓∧y␈↓␈αwhen␈αtypographically␈αconvenient
␈↓ ↓H␈↓and␈α∞the␈α∞linear␈α∞Algol␈α∞notation␈α∞␈↓↓x↑y␈↓␈α∂when␈α∞it␈α∞isn't.␈α∞ Of␈α∞course,␈α∞numerical␈α∞and␈α∂symbolic␈α∞calculation
␈↓ ↓H␈↓must often be combined, so that the function giving the length of a list can be written

␈↓ ↓H␈↓␈↓ ∧2␈↓↓length u ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ 0 ␈↓αelse␈↓↓ 1 + length ␈↓αd␈↓↓␈α∧u␈↓. 

␈↓ ↓H␈↓The internal notation for numerical functions is that used in the examples given:

␈↓ ↓H␈↓                ␈↓¬(PLUS X Y ... Z)␈↓ for ␈↓↓x+y+...+z␈↓,
␈↓ ↓H␈↓                ␈↓¬(TIMES X ... Z)␈↓ for ␈↓↓xy...z␈↓,
␈↓ ↓H␈↓                ␈↓¬(MINUS X)␈↓ for ␈↓↓-x␈↓,
␈↓ ↓H␈↓                ␈↓¬(DIFFERENCE X Y)␈↓ for ␈↓↓x-y␈↓,
␈↓ ↓H␈↓                ␈↓¬(QUOTIENT X Y)␈↓ for ␈↓↓x/y␈↓,
␈↓ ↓H␈↓                ␈↓¬(POWER X Y)␈↓ for ␈↓↓x␈↓∧y␈↓.

␈↓ ↓H␈↓        Since␈α∂numbers␈α∂that␈α∂form␈α∂part␈α∂of␈α∂list␈α∂structures␈α∂must␈α∂be␈α∂represented␈α∂by␈α∂pointers␈α∂anyway,
␈↓ ↓H␈↓there␈α⊃is␈α∩room␈α⊃for␈α∩a␈α⊃flag␈α∩distinguishing␈α⊃floating␈α∩point␈α⊃numbers␈α∩and␈α⊃integers.␈α∩ Therefore,␈α⊃the
␈↓ ↓H␈↓arithmetic␈α⊃operations␈α⊂are␈α⊃programmed␈α⊂to␈α⊃treat␈α⊂types␈α⊃dynamically,␈α⊂i.e.␈α⊃a␈α⊂variable␈α⊃may␈α⊃take␈α⊂an
␈↓ ↓H␈↓integer␈αvalue␈αat␈α
one␈αstep␈αof␈αcomputation␈α
and␈αa␈αreal␈αvalue␈α
at␈αanother.␈α The␈α
subroutines␈αrealizing
␈↓ ↓H␈↓the␈αarithmetic␈αfunctions␈αmake␈αthe␈αappropriate␈α
tests␈αand␈αcreate␈αresults␈αof␈αappropriate␈α
types.␈α This
␈↓ ↓H␈↓is␈α⊃slow␈α⊂compared␈α⊃to␈α⊃direct␈α⊂use␈α⊃of␈α⊂the␈α⊃machine's␈α⊃arithmetic␈α⊂instructions,␈α⊃so␈α⊂that␈α⊃LISP␈α⊃can␈α⊂be
␈↓ ↓H␈↓efficiently␈α
used␈α
only␈αwhen␈α
the␈α
numerical␈αcalculations␈α
are␈α
small␈αor␈α
at␈α
least␈αsmall␈α
compared␈α
to␈αthe
␈↓ ↓H␈↓symbolic calculations in a problem.
␈↓ ↓H␈↓␈↓ ¬oCHAPTER I␈↓ *23


␈↓ ↓H␈↓        Besides␈α
functions␈αof␈α
numbers␈α
we␈αneed␈α
predicates␈α
on␈αnumbers␈α
and␈α
the␈αusual␈α
=,␈α
<,␈α>,␈α
≤,␈αand␈α
≥
␈↓ ↓H␈↓are␈α_used␈α_with␈α→the␈α_internal␈α_names␈α_␈↓¬EQUAL,␈α→␈↓␈↓¬LESSP,␈α_␈↓␈↓¬GREATERP,␈α_␈↓␈↓¬LESSEQP,␈α→␈↓and␈α_␈↓¬GREATEREQP,
␈↓ ↓H␈↓¬␈↓respectively.␈α
 Not␈αall␈α
are␈α
implemented␈αin␈α
all␈αLISP␈α
systems,␈α
but␈αof␈α
course␈αthe␈α
remaining␈α
ones␈αcan
␈↓ ↓H␈↓be defined.  Besides that, the predicate ␈↓↓numberp␈↓ is used to distinguish numbers from other atoms.

␈↓ ↓H␈↓        It␈α_is␈α→worth␈α_remarking␈α→that␈α_including␈α_type␈α→flags␈α_in␈α→numbers␈α_would␈α→benefit␈α_many
␈↓ ↓H␈↓programming languages besides LISP and would not cost much in either storage or hardware.

␈↓ ↓H␈↓        As␈αa␈αfirst␈αexample␈αof␈αa␈αcombined␈αnumeric␈αand␈αsymbolic␈αcomputation,␈αhere␈αis␈αan␈αinterpreter
␈↓ ↓H␈↓for␈α∞expressions␈α∂with␈α∞sums␈α∂and␈α∞products.␈α∂ Assume␈α∞that␈α∂the␈α∞values␈α∂of␈α∞variables␈α∂are␈α∞given␈α∂in␈α∞an
␈↓ ↓H␈↓␈↓↓association␈↓ ␈↓↓list,␈↓ having the form

␈↓ ↓H␈↓                        (<variable1>.<value1>) ... (<variablen>.<valuen>)),

␈↓ ↓H␈↓e.g. ␈↓¬((X . 5) (Y . 9.3) (Z . 2.1))␈↓.

␈↓ ↓H␈↓        The function is

␈↓ ↓H␈↓        ␈↓↓numval[e,a] ← ␈↓αif␈↓↓ numberp e ␈↓αthen␈↓↓ e␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεe ␈↓αthen␈↓↓ ␈↓αd␈↓↓␈α∧assoc[e,a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e ␈↓αeq␈↓↓ ␈↓¬PLUS␈↓↓ ␈↓αthen␈↓↓ evplus[␈↓αd␈↓↓␈α∧e,a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e ␈↓αeq␈↓↓ ␈↓¬TIMES␈↓↓ ␈↓αthen␈↓↓ evtimes[␈↓αd␈↓↓␈α∧e,a]␈↓

␈↓ ↓H␈↓where

␈↓ ↓H␈↓        ␈↓↓evplus[u,a] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ 0 ␈↓αelse␈↓↓ numval[␈↓αa␈↓↓␈α∧u,a] + evplus[␈↓αd␈↓↓␈α∧u,a]␈↓,

␈↓ ↓H␈↓        ␈↓↓evtimes[u,a] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ 1 ␈↓αelse␈↓↓ numval[␈↓αa␈↓↓␈α∧u,a] ␈↓∧.␈↓↓ evtimes[␈↓αd␈↓↓␈α∧u,a]␈↓,

␈↓ ↓H␈↓and

␈↓ ↓H␈↓        ␈↓↓assoc[x,a] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧a ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧a ␈↓αeq␈↓↓ x ␈↓αthen␈↓↓ ␈↓αa␈↓↓␈α∧a ␈↓αelse␈↓↓ assoc[x,␈↓αd␈↓↓␈α∧a]␈↓.
␈↓ ↓H␈↓24␈↓ εH␈↓ H


␈↓ ↓H␈↓α␈↓ εChapter II

␈↓ ↓H␈↓α␈↓ β&HOW TO WRITE RECURSIVE FUNCTION DEFINITIONS




␈↓ ↓H␈↓1.  ␈↓αStatic and dynamic ways of programming.␈↓


␈↓ ↓H␈↓        In␈α∩ order␈α∩ to␈α∩ write␈α∩recursive␈α⊃function␈α∩definitions,␈α∩one␈α∩must␈α∩think␈α∩about␈α⊃programming
␈↓ ↓H␈↓differently␈αthan␈αis␈α customary␈α when␈α writing␈αprograms␈α in␈α languages␈αlike␈αFortran␈αor␈αAlgol␈αor␈αin
␈↓ ↓H␈↓machine␈α∪language.␈α∪ In␈α∪these␈α∪languages,␈α∪one␈α∪has␈α∪in␈α∪mind␈α∪the␈α∪state␈α∪of␈α∪the␈α∀ computation␈α∪ as
␈↓ ↓H␈↓represented␈α by␈α
 the␈α values␈α
of␈αcertain␈αvariables␈α
or␈αlocations␈α
in␈αthe␈αmemory␈α
of␈αthe␈α
machine,␈αand
␈↓ ↓H␈↓then␈α∞ one␈α∞ writes␈α∞ statements␈α∞ or␈α
 machine␈α∞instructions␈α∞in␈α∞order␈α∞to␈α
make␈α∞the␈α∞state␈α∞change␈α∞in␈α
an
␈↓ ↓H␈↓appropriate way.

␈↓ ↓H␈↓        When␈α∞writing␈α
LISP␈α∞recursive␈α∞functions␈α
one␈α∞thinks␈α∞differently.␈α
 Namely,␈α∞one␈α∞thinks␈α
about
␈↓ ↓H␈↓the␈αvalue␈αof␈αthe␈α function,␈α asks␈α for␈α what␈αvalues␈α of␈αthe␈αarguments␈αthe␈αvalue␈αof␈αthe␈αfunction␈αis
␈↓ ↓H␈↓immediate,␈α∞and,␈α∞given␈α
 an␈α∞ arbitrary␈α∞ values␈α
 of␈α∞ the␈α∞ arguments,␈α
 for␈α∞ what␈α∞ simpler␈α
arguments
␈↓ ↓H␈↓must␈α∪ the␈α∀ function␈α∪be␈α∀known␈α∪in␈α∀order␈α∪to␈α∪give␈α∀the␈α∪value␈α∀of␈α∪the␈α∀function␈α∪for␈α∀ the␈α∪ given
␈↓ ↓H␈↓arguments.␈α⊃ Let␈α⊃ us␈α⊃ take␈α⊂ a␈α⊃ numerical␈α⊃example;␈α⊃ namely,␈α⊂ suppose␈α⊃ we␈α⊃want␈α⊃to␈α⊃compute␈α⊂the
␈↓ ↓H␈↓function␈α ␈↓↓n!.␈↓␈α  For␈αwhat␈αargument␈α
is␈αthe␈αvalue␈αof␈αthe␈αfunction␈α
immediate.␈α  Clearly,␈α for␈α␈↓↓n␈↓␈α=␈α0␈α
 or
␈↓ ↓H␈↓␈↓↓n␈↓␈α=␈α1,␈αthe␈αvalue␈αis␈αimmediately␈αseen␈αto␈αbe␈α 1.␈α Moreover,␈αwe␈αcan␈αget␈αthe␈αvalue␈αfor␈αan␈αarbitrary␈α ␈↓↓n␈↓
␈↓ ↓H␈↓if␈αwe␈αknow␈α the␈α value␈α for␈α
␈↓↓n-1␈↓.␈α  Also,␈αwe␈αsee␈αthat␈αknowing␈α
the␈αvalue␈αfor␈α ␈↓↓n␈↓␈α=␈α1␈α
 is␈αredundant,
␈↓ ↓H␈↓since␈α
it␈α
can␈α
be␈α
obtained␈α
from␈α
the␈α
 ␈↓↓n␈↓␈α
=␈α
0␈α
 case␈α
by␈α
the␈α
 same␈α
 rule␈α
 as␈α
gets␈α
 it␈α
 for␈α
 a␈α∞ general␈α
 ␈↓↓n␈↓
␈↓ ↓H␈↓from the value for  ␈↓↓n-1␈↓.  All this talk leads to the simple recursive formula:

␈↓ ↓H␈↓        ␈↓↓n! ← ␈↓αif␈↓↓ n = 0 ␈↓αthen␈↓↓ 1 ␈↓αelse␈↓↓ n(n-1)!␈↓.

␈↓ ↓H␈↓        We␈αmay␈αregard␈αthis␈αas␈αa␈αstatic␈αway␈αof␈αlooking␈αat␈αprogramming.␈α We␈αask␈αwhat␈αsimpler␈α
cases
␈↓ ↓H␈↓the␈αgeneral␈αcase␈αof␈αour␈αfunction␈αdepends␈αon␈αrather␈α than␈α how␈α we␈α build␈αup␈αthe␈αdesired␈αstate␈αof
␈↓ ↓H␈↓the␈α∞computation.␈α
 One␈α∞often␈α
is␈α∞led␈α∞to␈α
believe␈α∞that␈α
 static␈α∞=␈α∞bad␈α
 and␈α∞  dynamic␈α
=␈α∞good,␈α∞but␈α
 in
␈↓ ↓H␈↓this␈α∩ case,␈α⊃ the␈α∩static␈α⊃way␈α∩is␈α⊃often␈α∩better␈α⊃than␈α∩the␈α⊃dynamic␈α∩way.␈α⊃ Perhaps␈α∩this␈α∩distinction␈α⊃is
␈↓ ↓H␈↓equivalent␈α~to␈α~what␈α≠some␈α~people␈α~call␈α~the␈α≠distinction␈α~between␈α~␈↓↓top-down␈↓␈α≠and␈α~␈↓↓bottom-up␈↓
␈↓ ↓H␈↓programming␈α⊂with␈α⊂␈↓↓static␈↓␈α⊂corresponding␈α⊂to␈α⊂␈↓↓top-down.␈α∂LISP␈↓␈α⊂offers␈α⊂both,␈α⊂but␈α⊂the␈α⊂static␈α⊂style␈α∂is
␈↓ ↓H␈↓better developed in LISP, and we will emphasize it.

␈↓ ↓H␈↓        Compare␈α
 the␈α∞ above␈α
 recursive␈α∞ definition␈α
with␈α∞the␈α
following␈α∞obvious␈α
Algol␈α∞program␈α
for
␈↓ ↓H␈↓computing  ␈↓↓n!:␈↓
␈↓ ↓H␈↓␈↓ ¬jCHAPTER II␈↓ *25



␈↓ ↓H␈↓                ␈↓αinteger procedure ␈↓↓factorial(n); ␈↓αinteger ␈↓↓s;
␈↓ ↓H␈↓↓        ␈↓αbegin
␈↓ ↓H␈↓α                ␈↓↓s := 1;
␈↓ ↓H␈↓↓        loop: ␈↓αif ␈↓↓n = 0 ␈↓αthen go to ␈↓↓done;
␈↓ ↓H␈↓↓                s := n*s;
␈↓ ↓H␈↓↓                n := n-1;
␈↓ ↓H␈↓↓                ␈↓αgo to ␈↓↓loop;
␈↓ ↓H␈↓↓        done: factorial := s;
␈↓ ↓H␈↓↓        ␈↓αend␈↓;

␈↓ ↓H␈↓        The␈α∞ LISP␈α∞program␈α∞is␈α∞shorter␈α∂and␈α∞clearer␈α∞in␈α∞this␈α∞particularly␈α∞favorable␈α∂ case.␈α∞  Actually,
␈↓ ↓H␈↓when␈α we␈α discuss␈α the␈α  mechanism␈α  of␈αrecursion,␈αit␈αwill␈αturn␈αout␈αthat␈αthe␈αLISP␈αprogram␈αwill␈αbe
␈↓ ↓H␈↓inefficient␈α⊃in␈α⊃using␈α∩the␈α⊃pushdown␈α⊃mechanism␈α⊃unnecessarily␈α∩and␈α⊃should␈α⊃be␈α⊃ replaced␈α∩by␈α⊃ the
␈↓ ↓H␈↓following␈α∪ somewhat␈α∪ longer␈α∀ program␈α∪that␈α∪corresponds␈α∪to␈α∀the␈α∪above␈α∪Algol␈α∀program␈α∪rather
␈↓ ↓H␈↓precisely:

␈↓ ↓H␈↓␈↓ ¬#␈↓↓n! ← fact(n, s),             ␈↓ 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ ∧∀␈↓↓fact(n, s) ← ␈↓αif␈↓↓ n = 0 ␈↓αthen␈↓↓ s ␈↓αelse␈↓↓ fact(n-1, n*s)␈↓. 

␈↓ ↓H␈↓In  fact,  compilers should produce the same object code from the two programs.



␈↓ ↓H␈↓2.  ␈↓αSimple list recursion.␈↓


␈↓ ↓H␈↓        About␈αthe␈αsimplest␈α
form␈αof␈αrecursion␈αin␈α
LISP␈αoccurs␈αwhen␈α one␈α
of␈αthe␈αarguments␈αis␈α
a␈αlist,
␈↓ ↓H␈↓the␈α
result␈α
is␈αimmediate␈α
when␈α
the␈αargument␈α
is␈α
null,␈α
and␈αotherwise␈α
we␈α
need␈αonly␈α
know␈α
the␈αresult␈α
for
␈↓ ↓H␈↓the␈α
d-part␈αof␈α
that␈α
argument.␈α Consider,␈α
for␈α
example,␈α ␈↓↓u*v␈↓,␈α
the␈α
result␈αof␈α
␈↓↓append␈↓ing␈α
the␈αlist␈α
␈↓↓v␈↓␈αto␈α
the
␈↓ ↓H␈↓list␈α␈↓↓u.␈↓␈αThe␈αresult␈αis␈αimmediate␈αfor␈α the␈α case␈α  ␈↓αn␈↓␈α∧␈↓↓u␈↓␈α  and␈αotherwise␈αdepends␈αon␈αthe␈αresult␈αfor␈α ␈↓αd␈↓␈α∧␈↓↓u.␈↓
␈↓ ↓H␈↓Thus, we have

␈↓ ↓H␈↓␈↓ ∧S␈↓↓u*v ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ v ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧u . [␈↓αd␈↓↓␈α∧u * v]␈↓. 

␈↓ ↓H␈↓On␈α
the␈α
other␈α
hand,␈α∞if␈α
we␈α
had␈α
tried␈α
to␈α∞recur␈α
on␈α
 ␈↓↓v␈↓␈α
 rather␈α
than␈α∞on␈α
 ␈↓↓u␈↓␈α
we␈α
would␈α
not␈α∞have␈α
been
␈↓ ↓H␈↓successful.␈α The␈αresult␈αwould␈αbe␈αimmediate␈αfor␈α␈↓αn␈↓␈α∧␈↓↓v,␈↓␈αbut␈α ␈↓↓u*v␈↓␈α cannot␈αbe␈αconstructed␈αin␈αany␈αdirect
␈↓ ↓H␈↓way␈α∞from␈α∞  ␈↓↓u*␈↓αd␈↓↓␈α∧v␈↓␈α∞without␈α∞ a␈α∞ function␈α∞ that␈α∞ puts␈α∂ an␈α∞ element␈α∞onto␈α∞the␈α∞end␈α∞of␈α∞a␈α∞list.␈α∂ (From␈α∞a
␈↓ ↓H␈↓strictly␈α∞list␈α∞point␈α∞of␈α∞view,␈α∞such␈α∞ a␈α∂ function␈α∞ would␈α∞ be␈α∞ as␈α∞elementary␈α∞ as␈α∞ ␈↓↓cons␈↓␈α∞ which␈α∂puts␈α∞an
␈↓ ↓H␈↓element␈α
onto␈α
the␈α
front␈α
of␈α
a␈α
list,␈α
but,␈α
when␈α
we␈α
consider␈α
the␈α
implementation␈α
of␈α
lists␈α
by␈αlist␈α
structures,
␈↓ ↓H␈↓we␈α see␈α that␈α the␈α function␈α
is␈αnot␈αso␈αelementary.␈α This␈αhas␈α
led␈αsome␈αpeople␈αto␈αconstruct␈αsystems␈α
in
␈↓ ↓H␈↓which␈α
lists␈α
are␈α
 bi-directional,␈α
 but,␈α
in␈α
 the␈α
 main,␈α
 this␈α
has␈α
turned␈α
out␈α
to␈α
be␈α
a␈α
bad␈αidea).␈α
 Anyway,
␈↓ ↓H␈↓it␈α∂is␈α∂usually␈α∞easier␈α∂to␈α∂recur␈α∞on␈α∂one␈α∂argument␈α∞of␈α∂a␈α∂function␈α∞than␈α∂ to␈α∂ recur␈α∞on␈α∂the␈α∂other.␈α∞ The
␈↓ ↓H␈↓␈↓↓append␈↓␈αfunction␈αis␈αmachine␈αcoded␈α
in␈αmost␈αLisp␈αsystems␈αin␈α
a␈αway␈αthat␈αallows␈αan␈αarbitrary␈α
number
␈↓ ↓H␈↓of arguments, e.g.  ␈↓¬(APPEND (QUOTE (A B)) (QUOTE (C D)) (QUOTE (E F))) is (A B C D E F)␈↓.
␈↓ ↓H␈↓26␈↓ ¬jCHAPTER II␈↓ H


␈↓ ↓H␈↓        It␈α
 is␈α often␈α
necessary␈αto␈α
represent␈αa␈α
correspondence␈αbetween␈α
the␈αelements␈α
of␈αa␈α
small␈α
set␈αof
␈↓ ↓H␈↓atoms␈αand␈αcertain␈α S-expressions␈α by␈α a␈αlist␈αstructure.␈α This␈αis␈αconveniently␈αdone␈αby␈αmeans␈αof␈αan
␈↓ ↓H␈↓association␈α
list␈α
which␈α
is␈α
a␈α
list␈α
of␈α
pairs,␈α
each␈α
pair␈α
consisting␈α
of␈α
 an␈α
 atom␈α
 and␈α
the␈α
corresponding␈α
S-
␈↓ ↓H␈↓expression. Thus the association list

␈↓ ↓H␈↓                        ␈↓¬((X . (PLUS A B)) (Y . C) (Z . (TIMES U V))␈↓,

␈↓ ↓H␈↓which would print as

␈↓ ↓H␈↓                        ␈↓¬((X PLUS A B)) (Y . C) (Z TIMES U V))␈↓,

␈↓ ↓H␈↓pairs␈α
 ␈↓¬X␈α∞␈↓␈α
with␈α∞ ␈↓¬(PLUS␈α
A␈α∞B)␈↓,␈α
 ␈↓¬Y␈α∞␈↓␈α
with␈α
 ␈↓¬C,␈α∞␈↓etc.␈α
We␈α∞need␈α
a␈α∞ function␈α
 to␈α∞tell␈α
 whether␈α∞ anything␈α
 is
␈↓ ↓H␈↓associated  with  the  atom   ␈↓↓x␈↓   in the association list  ␈↓↓a,␈↓ and if so, to tell us what. We have

␈↓ ↓H␈↓␈↓ α}␈↓↓assoc[x, a] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧a ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ ␈↓αif␈↓↓ x ␈↓αeq␈↓↓ ␈↓αaa␈↓↓␈α∧a ␈↓αthen␈↓↓ ␈↓αa␈↓↓␈α∧a ␈↓αelse␈↓↓ assoc[x, ␈↓αd␈↓↓␈α∧a].␈↓ 

␈↓ ↓H␈↓Its␈α
value␈αis␈α
  ␈↓¬NIL␈↓␈α
  if␈α nothing␈α
 is␈α associated␈α
 with␈α
  ␈↓↓x␈↓␈α  and␈α
 the␈αassociation␈α
pair␈α
otherwise.␈α E.g.
␈↓ ↓H␈↓␈↓↓assoc[␈↓¬X, ␈↓↓␈↓¬((X.W) (Y.V))␈↓↓] = ␈↓¬(X.W)␈↓↓␈↓.  ␈↓↓assoc␈↓ is also built in to most Lisp systems.

␈↓ ↓H␈↓        It␈α∩ commonly␈α∩happens␈α∩that␈α∩a␈α∩function␈α∩has␈α∩no␈α∩simple␈α∩recursion,␈α∩but␈α∩there␈α∩is␈α∪a␈α∩simple
␈↓ ↓H␈↓recursion␈α
for␈α
a␈α
function␈α
with␈αone␈α
more␈α
variable␈α
that␈α
 reduces␈α to␈α
the␈α
desired␈α
function␈α
when␈αthe
␈↓ ↓H␈↓extra variable is set to ␈↓¬NIL␈↓.  Thus

␈↓ ↓H␈↓␈↓ ¬0␈↓↓reverse[u] ← rev[x, ␈↓¬NIL␈↓↓]␈↓, 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ ∧#␈↓↓rev[u, v] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ v ␈↓αelse␈↓↓ rev[␈↓αd␈↓↓␈α∧u, ␈↓αa␈↓↓␈α∧u . v]␈↓. 

␈↓ ↓H␈↓␈↓↓reverse␈↓␈α
has␈α
a␈α
direct␈α
recursive␈αdefinition␈α
as␈α
discovered␈α
by␈α
S.␈αNess,␈α
but␈α
no one␈α
would␈α
want␈α
to␈αuse
␈↓ ↓H␈↓the␈αfollowing␈αin␈αactual␈αcomputation␈α nor␈αdoes␈α it␈αgenerate␈αmuch␈αunderstanding,␈αonly␈αappreciation
␈↓ ↓H␈↓of Mr. Ness's ingenuity:

␈↓ ↓H␈↓␈↓ ↓}␈↓↓reverse2[u] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ∨ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧u ␈↓αthen␈↓↓ u ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧reverse2[␈↓αd␈↓↓␈α∧u] . reverse2[␈↓αa␈↓↓␈α∧u. reverse2[␈↓αd␈↓↓␈α∧reverse2[␈↓αd␈↓↓␈α∧u]]]␈↓. 


␈↓ ↓H␈↓α␈↓ ε
Exercises

␈↓ ↓H␈↓        1.␈αUsing␈αthe␈αfunction␈α ␈↓↓member[x,␈αu]␈↓␈α defined␈αin␈αChapter␈αI␈αwhich␈α may␈αalso␈αbe␈αwritten␈α ␈↓↓x␈αε
␈↓ ↓H␈↓↓u␈↓,␈αwrite␈αfunction␈αdefinitions␈αfor␈αthe␈αunion␈α ␈↓↓u␈α∪␈αv␈↓␈α of␈αlists␈α ␈↓↓u␈↓␈α and␈α ␈↓↓v,␈↓␈αthe␈αintersection␈α ␈↓↓u␈α∩␈αv␈↓,␈α and
␈↓ ↓H␈↓the set  difference   ␈↓↓u-v␈↓.    What  is  wanted  should  be clear from the examples:

␈↓ ↓H␈↓                        ␈↓¬(A B C) ∪ (B C D) = (A B C D)␈↓,

␈↓ ↓H␈↓                        ␈↓¬(A B C) ∩ (B C D) = (B C)␈↓,

␈↓ ↓H␈↓and
␈↓ ↓H␈↓␈↓ ¬jCHAPTER II␈↓ *27


␈↓ ↓H␈↓                        ␈↓¬(A B C) - (B C D) = (A)␈↓.

␈↓ ↓H␈↓Pay␈α∂ attention␈α∞ to␈α∂getting␈α∂correct␈α∞the␈α∂trivial␈α∂cases␈α∞in␈α∂which␈α∞some␈α∂of␈α∂the␈α∞arguments␈α∂are␈α∂␈↓¬NIL␈↓.␈α∞ In
␈↓ ↓H␈↓general, it  is  important  to  understand clearly the trivial cases of functions.

␈↓ ↓H␈↓        2.␈α∂ Suppose␈α∂  ␈↓↓x␈↓␈α∂  takes␈α∂ numbers␈α∂ as␈α∂ values␈α⊂and␈α∂ ␈↓↓u␈↓␈α∂ takes␈α∂as␈α∂values␈α∂lists␈α∂of␈α⊂numbers␈α∂in
␈↓ ↓H␈↓ascending␈αorder,␈α
e.g.␈α ␈↓¬(2␈α
4␈α7)␈↓.␈α  Write␈α
 a␈αfunction␈α
  ␈↓↓merge[x,␈αu]␈↓␈α  whose␈α
 value␈α is␈α
obtained␈αfrom
␈↓ ↓H␈↓that␈α⊂of␈α∂ ␈↓↓u␈↓␈α⊂ by␈α∂putting␈α⊂ ␈↓↓x␈↓␈α∂ in␈α⊂ ␈↓↓u␈↓␈α∂ in␈α⊂its␈α∂proper␈α⊂ place.␈α∂    Thus␈α⊂␈↓↓merge[␈↓¬3,␈α∂␈↓↓␈↓¬(2␈α⊂4)␈↓↓]␈α∂=␈α⊂␈↓¬(2␈α∂3␈α⊂4)␈↓↓␈↓,␈α∂and
␈↓ ↓H␈↓␈↓↓merge[␈↓¬3, ␈↓↓␈↓¬(2 3)␈↓↓] = ␈↓¬(2 3 3)␈↓↓␈↓.

␈↓ ↓H␈↓        3.␈α
 Write␈α
 functions␈α∞ giving␈α
the␈α
union,␈α∞intersection,␈α
and␈α
set␈α∞difference␈α
of␈α
ordered␈α∞lists;␈α
the
␈↓ ↓H␈↓result is wanted as an ordered list.

␈↓ ↓H␈↓        Note␈α∞that␈α∞computing␈α∂these␈α∞functions␈α∞of␈α∞unordered␈α∂lists␈α∞ takes␈α∞a␈α∞ number␈α∂ of␈α∞comparisons
␈↓ ↓H␈↓proportional␈αto␈αthe␈αsquare␈αof␈αthe␈αnumber␈αof␈αelements␈αof␈αa␈αtypical␈αlist,␈αwhile␈αfor␈αordered␈αlists,␈α the
␈↓ ↓H␈↓number  of comparisons is proportional to the number of elements.

␈↓ ↓H␈↓        4.␈α Using␈α  ␈↓↓merge,␈↓␈αwrite␈αa␈αfunction␈α ␈↓↓sort␈↓␈α that␈αtransforms␈αan␈αunordered␈αlist␈αinto␈αan␈αordered
␈↓ ↓H␈↓list.

␈↓ ↓H␈↓        5.␈α∀Write␈α∀a␈α∀function␈α∀ ␈↓↓goodsort␈↓␈α∀ that␈α∃ sorts␈α∀ a␈α∀ list␈α∀ using␈α∀ a␈α∀number␈α∃ of␈α∀ comparisons
␈↓ ↓H␈↓proportional  to   ␈↓↓n log n␈↓, where  ␈↓↓n␈↓  is the length of the list to be sorted.



␈↓ ↓H␈↓3.  ␈↓αSimple S-expression recursion.␈↓


␈↓ ↓H␈↓        In␈αanother␈αclass␈αof␈αproblems,␈αthe␈αvalue␈αof␈α the␈α function␈α is␈αimmediate␈α for␈α atomic␈α
symbols,
␈↓ ↓H␈↓and␈α
for␈α
non␈α
atoms␈α
depends␈α
only␈α
on␈α
the␈α
values␈α
for␈α
 the␈α
a-part␈α
and␈α
the␈α
d-part␈α
of␈α
the␈α
argument.
␈↓ ↓H␈↓Thus   ␈↓↓subst␈↓ was defined by

␈↓ ↓H␈↓␈↓ ↓w␈↓↓subst[x, y, z] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεz ␈↓αthen␈↓↓ [␈↓αif␈↓↓ z ␈↓αeq␈↓↓ y ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ z] ␈↓αelse␈↓↓ subst[x, y, ␈↓αa␈↓↓␈α∧z] . subst[x , y , ␈↓αd␈↓↓␈α∧z]␈↓. 

␈↓ ↓H␈↓        Two␈αother␈α
examples␈αare␈α ␈↓↓equal␈↓␈α
 which␈αgives␈α the␈α
 equality␈α of␈αS-expressions␈α
 and␈α  ␈↓↓flatten␈↓
␈↓ ↓H␈↓which spreads an S-expression into a list of atoms.  They are defined by:

␈↓ ↓H␈↓␈↓ β|␈↓↓x = y ← x ␈↓αeq␈↓↓ y ∨ [¬␈↓αat␈↓↓␈αεx ∧ ¬␈↓αat␈↓↓␈αεy ∧ ␈↓αa␈↓↓␈α∧x = ␈↓αa␈↓↓␈α∧y ∧ ␈↓αd␈↓↓␈α∧x = ␈↓αd␈↓↓␈α∧y]␈↓, 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ ∧y␈↓↓flatten[x] ← flat[x, ␈↓¬NIL␈↓↓]           ␈↓ 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ β␈␈↓↓flat[x,y] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ x.y ␈↓αelse␈↓↓ flat[␈↓αa␈↓↓␈α∧x,flat[␈↓αd␈↓↓␈α∧x,y]]␈↓. 

␈↓ ↓H␈↓The kind of double recursion used in ␈↓↓flatten␈↓ is often useful.  ␈↓↓flatten␈↓ could also be written
␈↓ ↓H␈↓28␈↓ ¬jCHAPTER II␈↓ H


␈↓ ↓H␈↓␈↓ ∧	␈↓↓flat1 x ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ <x> ␈↓αelse␈↓↓ flat1 ␈↓αa␈↓↓␈α∧x * flat1 ␈↓αd␈↓↓␈α∧x␈↓, 

␈↓ ↓H␈↓which␈α∪is␈α∀a␈α∪bit␈α∪easier␈α∀to␈α∪follow␈α∪although␈α∀less␈α∪efficient,␈α∪because␈α∀the␈α∪␈↓↓append␈↓␈α∀function␈α∪copies
␈↓ ↓H␈↓unnecessarily.


␈↓ ↓H␈↓α␈↓ ε
Exercises

␈↓ ↓H␈↓        1.␈α⊃Write␈α⊃a␈α⊃predicate␈α⊃to␈α⊃tell␈α⊃whether␈α⊃a␈α⊃given␈α⊃atom␈α⊃occurs␈α⊃in␈α⊃a␈α⊃given␈α⊃S-expression,␈α⊃e.g.
␈↓ ↓H␈↓␈↓↓occur[␈↓¬B, ␈↓↓␈↓¬((A.B).C)␈↓↓] = ␈↓¬T␈↓↓␈↓.

␈↓ ↓H␈↓        2. Write a predicate to tell how  many  times  a  given  atom occurs in an S-expression.

␈↓ ↓H␈↓        3.␈α
 Write␈α
 a␈α
 function␈α
to␈αmake␈α
a␈α
list␈α
without␈α
duplications␈αof␈α
the␈α
atoms␈α
occurring␈α
in␈α
an␈αS-
␈↓ ↓H␈↓expression.

␈↓ ↓H␈↓        4.␈α∂Write␈α∂a␈α∂function␈α∂to␈α⊂make␈α∂a␈α∂list␈α∂of␈α∂all␈α∂ atoms␈α⊂ that␈α∂ occur␈α∂more␈α∂  than␈α∂  once␈α⊂  in␈α∂  a
␈↓ ↓H␈↓given  S-expression  paired  with  their multiplicities.

␈↓ ↓H␈↓        5.␈α∂Write␈α∂a␈α∞predicate␈α∂to␈α∂tell␈α∂whether␈α∞an␈α∂S-expression␈α∂has␈α∂more␈α∞than␈α∂one␈α∂occurrence␈α∂of␈α∞a
␈↓ ↓H␈↓given S-expression as a sub-expression.



␈↓ ↓H␈↓4.  ␈↓αOther structural recursions.␈↓


␈↓ ↓H␈↓        When␈α⊗lists␈α⊗are␈α⊗used␈α⊗to␈α⊗represent␈α⊗algebraic␈α⊗expressions,␈α⊗functions␈α⊗of␈α⊗these␈α⊗algebraic
␈↓ ↓H␈↓expressions␈α∃often␈α∃have␈α∀a␈α∃recursive␈α∃form␈α∀closely␈α∃related␈α∃to␈α∀the␈α∃inductive␈α∃definition␈α∃of␈α∀the
␈↓ ↓H␈↓expressions.␈α∂ Suppose,␈α∞for␈α∂example,␈α∞that␈α∂sums␈α∂and␈α∞products␈α∂are␈α∞represented␈α∂respectively␈α∂by␈α∞the
␈↓ ↓H␈↓forms␈α ␈↓¬(PLUS␈αX␈αY)␈↓↓␈↓¬␈α and␈α ␈↓␈↓¬(TIMES␈α
␈↓X␈αY)␈↓↓␈↓␈α and␈αthat␈αthe␈αvalues␈α
of␈αvariables␈αare␈αgiven␈αon␈αan␈αa-list.␈α
 We
␈↓ ↓H␈↓can write a recursive formula for the value of an expression as follows:

␈↓ ↓H␈↓        ␈↓↓value[e, a] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεe ␈↓αthen␈↓↓ ␈↓αd␈↓↓␈α∧assoc[e, a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e ␈↓αeq␈↓↓ ␈↓¬PLUS ␈↓↓␈↓αthen␈↓↓ value[␈↓αad␈↓↓␈α∧e, a] + value[␈↓αadd␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e ␈↓αeq␈↓↓ ␈↓¬TIMES ␈↓↓␈↓αthen␈↓↓ value[␈↓αad␈↓↓␈α∧e, a]  ␈↓β.␈↓↓ value[␈↓αadd␈↓↓␈α∧e, a]␈↓.

␈↓ ↓H␈↓On␈α
the␈αother␈α
hand,␈α
suppose␈αthat␈α
sums␈αand␈α
products␈α
are␈αnot␈α
restricted␈α
to␈αhave␈α
just␈αtwo␈α
arguments;
␈↓ ↓H␈↓then we must use auxiliary functions to define the value of an expression, as follows:

␈↓ ↓H␈↓        ␈↓↓value[e, a] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεe ␈↓αthen␈↓↓ ␈↓αd␈↓↓␈α∧assoc[e, a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e ␈↓αeq␈↓↓ ␈↓¬PLUS ␈↓↓␈↓αthen␈↓↓ vplus[␈↓αd␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e ␈↓αeq␈↓↓ ␈↓¬TIMES ␈↓↓␈↓αthen␈↓↓ vtimes[␈↓αd␈↓↓␈α∧e, a]␈↓.

␈↓ ↓H␈↓where

␈↓ ↓H␈↓        ␈↓↓vplus[u, a] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ 0 ␈↓αelse␈↓↓ value[␈↓αa␈↓↓␈α∧u, a] + vplus[␈↓αd␈↓↓␈α∧u, a]␈↓,
␈↓ ↓H␈↓␈↓ ¬jCHAPTER II␈↓ *29


␈↓ ↓H␈↓and

␈↓ ↓H␈↓        ␈↓↓vtimes[u, a] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ 1 ␈↓αelse␈↓↓ value[␈↓αa␈↓↓␈α∧u, a] ␈↓β.␈↓↓ vtimes[␈↓αd␈↓↓␈α∧u, a]␈↓.

␈↓ ↓H␈↓In␈α∂both␈α⊂cases,␈α∂the␈α∂recursion␈α⊂form␈α∂is␈α∂related␈α⊂to␈α∂the␈α∂structure␈α⊂of␈α∂the␈α∂algebraic␈α⊂expressions␈α∂more
␈↓ ↓H␈↓closely than to the structure of S-expressions or lists.



␈↓ ↓H␈↓5.  ␈↓αTree search recursion.␈↓


␈↓ ↓H␈↓        We␈αbegin␈αwith␈αa␈αgeneral␈αdepth␈αfirst␈αtree␈αsearch␈αfunction.␈α It␈αcan␈αbe␈αused␈αto␈αsearch␈αspecific
␈↓ ↓H␈↓trees␈α∃of␈α∃possibilities␈α∃by␈α∀defining␈α∃three␈α∃auxiliary␈α∃functions␈α∃in␈α∀a␈α∃way␈α∃that␈α∃depends␈α∃on␈α∀the
␈↓ ↓H␈↓application.  We have

␈↓ ↓H␈↓␈↓ αU␈↓↓search p ← ␈↓αif␈↓↓ lose p ␈↓αthen␈↓↓ ␈↓¬LOSE ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ter p ␈↓αthen␈↓↓ p ␈↓αelse␈↓↓ searchlis[successors p]␈↓ 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ α⊃␈↓↓searchlis u ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓¬LOSE ␈↓↓ ␈↓αelse␈↓↓ {search ␈↓αa␈↓↓␈α∧u}[λx: ␈↓αif␈↓↓ x = ␈↓¬LOSE ␈↓↓␈↓αthen␈↓↓ searchlis ␈↓αd␈↓↓␈α∧u ␈↓αelse␈↓↓ x]␈↓. 

␈↓ ↓H␈↓In␈αthe␈α
applications,␈αwe␈α start␈α
with␈αa␈α
position␈α␈↓↓p␈↓β0␈↓↓␈↓,␈α and␈α
we␈αare␈α
looking␈αfor␈α a␈α
win␈αin␈α
the␈αsuccessor
␈↓ ↓H␈↓tree␈α∞of␈α∞␈↓↓p␈↓β0␈↓↓␈↓.␈α∂ Certain␈α∞positions␈α∞lose␈α∞and␈α∂ there␈α∞is␈α∞ no␈α∞point␈α∂looking␈α∞ at␈α∞their␈α∞ successors.␈α∂ This␈α∞is
␈↓ ↓H␈↓decided␈α∂ by␈α∞the␈α∂predicate␈α∂␈↓↓lose.␈↓␈α∞  A␈α∂position␈α∂ is␈α∞a␈α∂win␈α∂if␈α∞it␈α∂ doesn't␈α∂ lose␈α∞ and␈α∂ it␈α∂ satisfies␈α∞ the
␈↓ ↓H␈↓predicate␈α␈↓↓ter.␈↓␈α The␈αsuccessors␈αof␈αa␈αposition␈αare␈αgiven␈αby␈αthe␈αfunction␈α␈↓↓successors,␈↓␈αand␈α the␈α value
␈↓ ↓H␈↓of␈α␈↓↓search␈α
 p␈↓␈α is␈α
 the␈α winning␈α
position.␈α   No␈α
non-losing␈αposition␈α
should␈αhave␈α
the␈α name␈αLOSE␈α
or
␈↓ ↓H␈↓the function  won't work properly.

␈↓ ↓H␈↓        Simple␈αS-expression␈αrecursion␈αcan␈αbe␈αregarded␈αas␈αa␈αspecial␈αcase␈αof␈αdepth␈αfirst␈αrecursion.␈α It
␈↓ ↓H␈↓is␈αspecial␈αin␈αthat␈αthere␈α
are␈αexactly␈αtwo␈αbranches,␈αbut␈αeven␈α
more␈αimportant,␈αthe␈αtree␈αis␈αthe␈α
tree␈αof
␈↓ ↓H␈↓parts␈α
of␈αthe␈α
S-expression␈αand␈α
is␈αpresent␈α
at␈αthe␈α
beginning␈αof␈α
the␈αcalculation.␈α
 In␈αcase␈α
of␈αtree␈α
search
␈↓ ↓H␈↓recursion, the tree is generated by the ␈↓↓successors␈↓  function.

␈↓ ↓H␈↓        Our␈α
first␈α
application␈α
is␈α
 finding␈α
a␈α
path␈α
from␈α
an␈α
 initial␈α
node␈α
to␈α
a␈α
final␈α
node␈α
 in␈α
a␈αgraph
␈↓ ↓H␈↓represented␈αby␈αa␈αlist␈αstructure␈αas␈αdescribed␈αin␈αchapter␈αI.␈α  A␈αposition␈αis␈αa␈αpath␈α starting␈αfrom␈αthe
␈↓ ↓H␈↓initial␈α∂ node␈α∂and␈α∂ continuing␈α∂to␈α∂ some␈α∂intermediate␈α∞ node␈α∂and␈α∂ is␈α∂represented␈α∂ by␈α∂a␈α∂list␈α∂ of␈α∞its
␈↓ ↓H␈↓nodes  in reverse order.   The three  functions for this application are

␈↓ ↓H␈↓␈↓ ¬/␈↓↓lose p ← ␈↓αa␈↓↓␈α∧p ε ␈↓αd␈↓↓␈α∧p ,       ␈↓ 

␈↓ ↓H␈↓␈↓ ¬$␈↓↓ter p ← [␈↓αa␈↓↓␈α∧p = final] ,     ␈↓ 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ βr␈↓↓successors p ← mapcar[␈↓αd␈↓↓␈α∧assoc[␈↓αa␈↓↓␈α∧p, graph], λx: x . p]␈↓. 
␈↓ ↓H␈↓30␈↓ ¬jCHAPTER II␈↓ H


␈↓ ↓H␈↓        Another␈α
example␈α
is␈α
the␈α
so-called␈α
␈↓αInstant␈αInsanity␈↓␈α
puzzle.␈α
 There␈α
are␈α
four␈α
cubical␈αblocks,
␈↓ ↓H␈↓and␈α∞each␈α∞face␈α∞of␈α∞each␈α∞block␈α∞is␈α∞colored␈α∞with␈α
one␈α∞of␈α∞four␈α∞colors.␈α∞ The␈α∞object␈α∞of␈α∞the␈α∞puzzle␈α∞is␈α
to
␈↓ ↓H␈↓build␈αa␈αtower␈αof␈αall␈αfour␈αblocks␈αsuch␈αthat␈αeach␈αvertical␈αface␈αof␈αthe␈αtower␈αinvolves␈αall␈αfour␈αcolors.
␈↓ ↓H␈↓In␈α∃order␈α∃to␈α∀use␈α∃the␈α∃above␈α∃defined␈α∀function␈α∃␈↓↓search␈↓␈α∃for␈α∃this␈α∀purpose,␈α∃we␈α∃must␈α∃define␈α∀the
␈↓ ↓H␈↓representation␈α∩of␈α∩positions␈α∩and␈α∩give␈α∩the␈α∩functions␈α∩␈↓↓lose,␈↓␈α∩␈↓↓ter,␈↓␈α∩and␈α∩␈↓↓successors.␈↓␈α∩  A␈α∩position␈α∩is
␈↓ ↓H␈↓represented␈αby␈αa␈αlist␈αof␈αlists␈α-␈αone␈αfor␈αeach␈αface␈αof␈αthe␈αtower.␈α Each␈αsublist␈αis␈αthe␈αlist␈αof␈αcolors␈αof
␈↓ ↓H␈↓the␈αfaces␈α
of␈αthe␈αblocks␈α
showing␈αin␈α
that␈αface.␈α We␈α
shall␈αassume␈α
that␈αthe␈αblocks␈α
are␈αdescribed␈αin␈α
the
␈↓ ↓H␈↓following␈α∂longwinded␈α∂but␈α∂convenient␈α∂way.␈α∂ (We'll␈α∂take␈α∂up␈α∂precomputing␈α∂this␈α∂description␈α∂later.)
␈↓ ↓H␈↓For␈α⊃each␈α∩block␈α⊃there␈α∩is␈α⊃a␈α⊃list␈α∩of␈α⊃the␈α∩24␈α⊃orientations␈α⊃of␈α∩the␈α⊃block␈α∩where␈α⊃each␈α∩orientation␈α⊃is
␈↓ ↓H␈↓described␈α∪as␈α∩a␈α∪list␈α∩of␈α∪the␈α∩colors␈α∪around␈α∪the␈α∩vertical␈α∪faces␈α∩of␈α∪the␈α∩block␈α∪when␈α∩it␈α∪is␈α∪in␈α∩that
␈↓ ↓H␈↓orientation.  Thus the puzzle is described by a list of lists of lists which we shall call ␈↓↓puzz.␈↓

␈↓ ↓H␈↓        We now have

␈↓ ↓H␈↓␈↓ ¬A␈↓↓p␈↓β0␈↓↓ = ␈↓¬(NIL NIL NIL NIL)␈↓↓␈↓, 

␈↓ ↓H␈↓␈↓ ¬	␈↓↓lose p ← orlis[p, λu: ␈↓αa␈↓↓␈α∧u ε ␈↓αd␈↓↓␈α∧u]␈↓, 

␈↓ ↓H␈↓␈↓ ¬2␈↓↓ter p ← [length ␈↓αa␈↓↓␈α∧p = 4]␈↓, 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ αB␈↓↓successors p ← mapcar[␈↓αa␈↓↓␈α∧nth[puzz, 1 + length ␈↓αa␈↓↓␈α∧p], λx: mapcar2[p, x, λyz: z.y]]␈↓, 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ αv␈↓↓mapcar2[u, v, f] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ f[␈↓αa␈↓↓␈α∧u, ␈↓αa␈↓↓␈α∧v] . mapcar2[␈↓αd␈↓↓␈α∧u, ␈↓αd␈↓↓␈α∧v, f]␈↓. 

␈↓ ↓H␈↓        Getting␈α
the␈α
initial␈α
position␈αin␈α
the␈α
desired␈α
form␈α
is␈αas␈α
complicated␈α
a␈α
computation␈α
as␈αthe␈α
actual
␈↓ ↓H␈↓tree␈α
search.␈α
 It␈α
can␈α
be␈α
conveniently␈α
done␈αby␈α
a␈α
sequence␈α
of␈α
assignment␈α
statements␈α
starting␈α
with␈αa
␈↓ ↓H␈↓description of the blocks:

␈↓ ↓H␈↓␈↓ β␈↓↓puzz1 ← ␈↓¬((G B B W R G) (G G B G W R) (G W W R B R) (G G R B W W))␈↓↓␈↓. 

␈↓ ↓H␈↓Here␈αeach␈αblock␈αis␈αrepresented␈αby␈αa␈αlist␈αof␈αthe␈αcolors␈αof␈αthe␈αfaces␈αstarting␈αwith␈αthe␈αtop␈αface,␈αgoing
␈↓ ↓H␈↓around the sides in a clockwise direction and finishing with the bottom face.

␈↓ ↓H␈↓        We␈αneed␈αto␈α
go␈αfrom␈αthis␈α
description␈αof␈αthe␈α
blocks␈αto␈αa␈α
list␈αof␈αthe␈α
possible␈αcycles␈αof␈αcolors␈α
on
␈↓ ↓H␈↓the␈αvertical␈αfaces␈αfor␈αthe␈α24␈αorientations␈αof␈αthe␈αblock.␈α This␈αnot␈αeasy,␈αbecause␈αthe␈αorder␈αin␈αwhich
␈↓ ↓H␈↓we␈α
have␈α
given␈αthe␈α
colors␈α
is␈α
not␈αinvariant␈α
under␈α
rotations␈α
of␈αthe␈α
block.␈α
 An␈α
easy␈αway␈α
out␈α
is␈αto␈α
start
␈↓ ↓H␈↓with␈αa␈αblock␈αwhose␈αfaces␈αare␈αassigned␈αthe␈αnumbers␈α1␈αthru␈α6␈αstarting␈αwith␈αthe␈αtop,␈αgoing␈α
clockwise
␈↓ ↓H␈↓around␈αthe␈αsides␈αand␈αfinishing␈αwith␈αthe␈αbottom.␈α We␈αwrite␈αdown␈αone␈αcycle␈αof␈αside␈αcolors␈αfor␈αeach
␈↓ ↓H␈↓choice␈α∩of␈α⊃the␈α∩face␈α⊃put␈α∩on␈α⊃top␈α∩and␈α⊃get␈α∩the␈α⊃list␈α∩of␈α⊃all␈α∩24␈α⊃cycles␈α∩by␈α⊃appending␈α∩the␈α∩results␈α⊃of
␈↓ ↓H␈↓generating the cyclic permutations of the cycles.  All this is accomplished by the assignment.

␈↓ ↓H␈↓                ␈↓↓puzz2 ← cycles[␈↓¬(2 3 4 5)␈↓↓] * cycles[␈↓¬(2 5 4 3)␈↓↓] * cycles[␈↓¬(1 2 6 4)␈↓↓␈↓
␈↓ ↓H␈↓                        ␈↓↓* cycles[␈↓¬(1 4 6 2)␈↓↓] * cycles[␈↓¬(1 3 6 5)␈↓↓] * cycles[␈↓¬(1 5 6 3)␈↓↓]␈↓,
␈↓ ↓H␈↓␈↓ ¬jCHAPTER II␈↓ *31


␈↓ ↓H␈↓where the function ␈↓↓cycles␈↓ is defined by

␈↓ ↓H␈↓␈↓ ∧@␈↓↓cycles u ← maplist[u, λx: x * upto[u, x]]␈↓ 

␈↓ ↓H␈↓with the auxiliary function

␈↓ ↓H␈↓␈↓ βl␈↓↓upto[u, x] ← ␈↓αif␈↓↓ x ␈↓αeq␈↓↓ u ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧u . upto[␈↓αd␈↓↓␈α∧u, x]␈↓. 

␈↓ ↓H␈↓Next␈α∞we␈α∞create␈α∞for␈α∞each␈α∞block␈α∞a␈α∞list␈α∞of␈α∞substitutions␈α∞expressing␈α∞the␈α∞colors␈α∞of␈α∞the␈α∂six␈α∞numbered
␈↓ ↓H␈↓faces.  We have

␈↓ ↓H␈↓␈↓ βw␈↓↓puzz3 ← mapcar[puzz1, λx: prup[␈↓¬(1 2 3 4 5 6)␈↓↓, x]]␈↓, 

␈↓ ↓H␈↓and we use these substitutions to get for each block the list of 24 orientations of the block. Thus

␈↓ ↓H␈↓␈↓ ∧#␈↓↓puzz4 ← mapcar[puzz3, λs: sublis[s, puzz3]]␈↓. 

␈↓ ↓H␈↓␈↓↓puzz4␈↓␈αhas␈αall␈α24␈αorientations␈αof␈αthe␈αfirst␈αblock␈αwhile␈αfor␈αsymmetry␈αreasons␈αwe␈αneed␈αonly␈αconsider
␈↓ ↓H␈↓three as distinct, say the first, ninth, and seventeenth.  So we finally get

␈↓ ↓H␈↓␈↓ αf␈↓↓puzz ← <␈↓αa␈↓↓␈α∧nth[␈↓αa␈↓↓␈α∧puzz4, 1], ␈↓αa␈↓↓␈α∧nth[␈↓αa␈↓↓␈α∧puzz4, 9], ␈↓αa␈↓↓␈α∧nth[␈↓αa␈↓↓␈α∧puzz4, 17]> . ␈↓αd␈↓↓␈α∧puzz4␈↓. 

␈↓ ↓H␈↓The program when compiled runs about 11 seconds on the KA-10.

␈↓ ↓H␈↓        A␈αmore␈αsophisticated␈αrepresentation␈αof␈αface␈α
cycles␈αand␈αpartial␈αtowers␈αmakes␈αa␈αfactor␈α
of␈αten
␈↓ ↓H␈↓speedup␈αwithout␈αchanging␈αthe␈αbasic␈αsearch␈αalgorithm.␈α A␈αface␈αcycle␈αis␈αrepresented␈αby␈α16␈αbits␈αin␈αa
␈↓ ↓H␈↓word␈α
four␈α
for␈α
each␈α
face␈α
a␈α
particular␈α
one␈α
of␈α
which␈α
being␈α
turned␈α
on␈α
tells␈α
us␈α
the␈α
color␈α
of␈α
the␈αface.␈α
 If
␈↓ ↓H␈↓we␈α␈↓αor␈↓␈αthese␈αwords␈αtogether␈αfor␈αthe␈αblocks␈αin␈αa␈αpartial␈αtower␈αwe␈αget␈αa␈αword␈αwhich␈αtells␈αus␈αfor␈αeach
␈↓ ↓H␈↓face␈αof␈αthe␈αtower␈αwhat␈αcolors␈αhave␈αbeen␈αused.␈α A␈αparticular␈αface␈αcycle␈αfrom␈αthe␈αnext␈αblock␈αcan␈αbe
␈↓ ↓H␈↓added␈α∂to␈α∂the␈α⊂tower␈α∂if␈α∂the␈α∂␈↓αand␈↓␈α⊂of␈α∂its␈α∂word␈α⊂with␈α∂the␈α∂word␈α∂representing␈α⊂the␈α∂tower␈α∂is␈α⊂zero.␈α∂ We
␈↓ ↓H␈↓represent␈α
a␈α
position␈α
by␈α
a␈α
list␈α
of␈α
words␈α
representing␈α
its␈α
partial␈α
towers␈α
with␈α
0␈α
as␈α
the␈α
last␈αelement␈α
and
␈↓ ↓H␈↓the␈α
highest␈α
partial␈α
tower␈α
as␈α
the␈α
first␈α
element.␈α
 The␈α
virtue␈α
of␈α
this␈α
representation␈α
is␈α
that␈α
it␈αmakes
␈↓ ↓H␈↓the␈αdescription␈αof␈αthe␈αalgorithm␈αshort.␈α The␈αinitial␈αposition␈αis␈α␈↓¬(0)␈↓.␈α The␈αnew␈α␈↓↓puzz␈↓␈αcan␈α
be␈αformed
␈↓ ↓H␈↓from the old one by the assignment

␈↓ ↓H␈↓␈↓ ∧.␈↓↓puzza ← mapcar[puzz, λx: mapcar[x, zap]]␈↓ 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ ∧→␈↓↓zap v ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧v ␈↓αthen␈↓↓ 0 ␈↓αelse␈↓↓ poo ␈↓αa␈↓↓␈α∧v + 16 * zap ␈↓αd␈↓↓␈α∧v␈↓ 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ α⎇␈↓↓poo x ← ␈↓αif␈↓↓ x = ␈↓¬R ␈↓↓␈↓αthen␈↓↓ 1 ␈↓αelse␈↓↓ if x = ␈↓¬W ␈↓↓␈↓αthen␈↓↓ 2 ␈↓αelse␈↓↓ ␈↓αif␈↓↓ x = ␈↓¬G ␈↓↓␈↓αthen␈↓↓ 4 ␈↓αelse␈↓↓ 8␈↓. 

␈↓ ↓H␈↓Now we need the new functions ␈↓↓lose,␈↓ ␈↓↓ter,␈↓ and ␈↓↓successors.␈↓   These are

␈↓ ↓H␈↓␈↓ ¬O␈↓↓lose p ← ␈↓αfalse␈↓↓ ,    ␈↓ 
␈↓ ↓H␈↓32␈↓ ¬jCHAPTER II␈↓ H


␈↓ ↓H␈↓␈↓ ¬9␈↓↓ter p ← [length p = 5]␈↓, 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ α≤␈↓↓successors p ← mapchoose[␈↓αa␈↓↓␈α∧nth[puzza, length p], λx: ␈↓αa␈↓↓␈α∧p ␈↓¬and ␈↓↓x = 0, λx: [␈↓αa␈↓↓␈α∧p ␈↓¬or ␈↓↓x] . p]␈↓. 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓                ␈↓↓mapchoose[u, pred, fn] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ pred ␈↓αa␈↓↓␈α∧u ␈↓αthen␈↓↓ fn[␈↓αa␈↓↓␈α∧u] . mapchoose[␈↓αd␈↓↓␈α∧u, pred, fn] ␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ mapchoose[␈↓αd␈↓↓␈α∧u, pred, fn]␈↓.

␈↓ ↓H␈↓␈↓↓lose␈↓␈αis␈αtrivial,␈αbecause␈αthe␈α␈↓↓mapchoose␈↓␈αis␈αused␈αto␈αmake␈αsure␈αthat␈αonly␈αnon-losing␈αnew␈αpositions␈αare
␈↓ ↓H␈↓generated␈α∂by␈α∂␈↓↓successors.␈↓␈α∂This␈α∂version␈α⊂runs␈α∂in␈α∂a␈α∂little␈α∂less␈α⊂than␈α∂one␈α∂second␈α∂on␈α∂the␈α⊂KA-10.␈α∂ A
␈↓ ↓H␈↓greater␈α⊃speedup␈α⊂can␈α⊃be␈α⊂made␈α⊃by␈α⊃the␈α⊂application␈α⊃of␈α⊂some␈α⊃mathematics.␈α⊂ In␈α⊃fact,␈α⊃with␈α⊂enough
␈↓ ↓H␈↓mathematics, extensive tree search is unnecessary in this problem.

␈↓ ↓H␈↓        ␈↓↓search␈↓␈α∞is␈α∞used␈α
when␈α∞we␈α∞want␈α
to␈α∞search␈α∞a␈α∞tree␈α
of␈α∞possibilities␈α∞for␈α
a␈α∞solution␈α∞to␈α∞a␈α
problem.
␈↓ ↓H␈↓Naturally␈α∞we␈α∞can␈α∞do␈α∞other␈α∞things␈α∞with␈α∞tree␈α∞search␈α∞recursion␈α∞than␈α∞just␈α∞search.␈α∞ For␈α∞example␈α
we
␈↓ ↓H␈↓may␈α
want␈αto␈α
find␈αall␈α
solutions␈α
to␈αa␈α
problem.␈α This␈α
can␈αbe␈α
done␈α
with␈αa␈α
function␈α␈↓↓allsol␈↓␈α
that␈αuses␈α
the
␈↓ ↓H␈↓same ␈↓↓lose,␈↓ ␈↓↓ter,␈↓ and ␈↓↓successors␈↓ functions as does ␈↓↓search.␈↓ The simplest way to write ␈↓↓allsol␈↓ is

␈↓ ↓H␈↓␈↓ α'␈↓↓allsol p ← ␈↓αif␈↓↓ lose p ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ ␈↓αif␈↓↓ ter p ␈↓αthen␈↓↓ <p> ␈↓αelse␈↓↓ mapapp[successors p, allsol]␈↓, 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ β*␈↓↓mapapp[u, fn] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ fn[␈↓αa␈↓↓␈α∧u] * mappap[␈↓αd␈↓↓␈α∧u, fn]␈↓. 

␈↓ ↓H␈↓This␈αform␈αof␈αthe␈αfunction␈αis␈αsomewhat␈αinefficient␈αbecause␈αof␈αall␈αthe␈α␈↓↓append␈↓ing.␈α A␈αmore␈αefficient
␈↓ ↓H␈↓form uses an auxiliary function as follows:

␈↓ ↓H␈↓␈↓ ¬*␈↓↓allsol p ← allsola[p, ␈↓¬NIL␈↓↓]␈↓ 

␈↓ ↓H␈↓                        ␈↓↓allsola[p, found] ← ␈↓αif␈↓↓ lose p ␈↓αthen␈↓↓ found␈↓
␈↓ ↓H␈↓                                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ter p ␈↓αthen␈↓↓ p . found␈↓
␈↓ ↓H␈↓                                ␈↓↓␈↓αelse␈↓↓ allsolb[successors p, found]␈↓,

␈↓ ↓H␈↓␈↓ αq␈↓↓allsolb[u, found] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ found ␈↓αelse␈↓↓ allsolb[␈↓αd␈↓↓␈α∧u, allsola[␈↓αa␈↓↓␈α∧u, found]]␈↓. 

␈↓ ↓H␈↓The␈α⊃recursive␈α⊂program␈α⊃structure␈α⊂that␈α⊃arises␈α⊂here␈α⊃is␈α⊃common␈α⊂when␈α⊃a␈α⊂list␈α⊃is␈α⊂to␈α⊃be␈α⊃formed␈α⊂by
␈↓ ↓H␈↓recurring through a list structure.
␈↓ ↓H␈↓␈↓ ¬jCHAPTER II␈↓ *33


␈↓ ↓H␈↓6.  ␈↓αGame trees.␈↓


␈↓ ↓H␈↓        The␈α
positions␈α
that␈α
can␈α
be␈α
reached␈α
from␈α
an␈α
initial␈α
position␈α
in␈α
a␈α
 game␈α
 form␈α
 a␈α∞ tree,␈α
and
␈↓ ↓H␈↓deciding␈α
what␈αmove␈α
to␈α
make␈αoften␈α
involves␈α
searching␈αthis␈α
tree.␈α
 However,␈αgame␈α
trees␈αare␈α
searched
␈↓ ↓H␈↓in␈αa␈αdifferent␈αway␈α than␈αthe␈αtrees␈αwe␈α
have␈αlooked␈αat,␈αbecause␈αthe␈αopposing␈αinterests␈αof␈αthe␈α
players
␈↓ ↓H␈↓makes␈αit␈αnot␈αa␈αsearch␈αfor␈αa␈αjoint␈αline␈α of␈α play␈α that␈αwill␈α lead␈α to␈α the␈α first␈α player␈αwinning,␈αbut
␈↓ ↓H␈↓rather a search for a strategy that will lead to a win regardless of what the other  player does.

␈↓ ↓H␈↓        The␈α∃  simplest␈α∃ situation␈α∃ is␈α∃ characterized␈α∃ by␈α∃ a␈α∃ function␈α∃␈↓↓successors␈↓␈α∃that␈α∃gives␈α∃the
␈↓ ↓H␈↓positions␈αthat␈αcan␈αbe␈αreached␈αin␈α one␈αmove,␈α a␈α predicate␈α ␈↓↓ter␈↓␈α that␈α tells␈α when␈αa␈αposition␈αis␈αto␈αbe
␈↓ ↓H␈↓regarded␈α as␈α terminal␈α for␈α the␈α given␈α analysis,␈α and␈α a␈α  function␈α␈↓↓imval␈↓␈α that␈α gives␈α a␈α number
␈↓ ↓H␈↓approximating␈α∞ the␈α∞ value␈α∞ of␈α∞the␈α
position␈α∞to␈α∞one␈α∞of␈α∞the␈α
 players.␈α∞  We␈α∞ shall␈α∞ call␈α∞ this␈α
 player
␈↓ ↓H␈↓the␈α
maximizing␈α player␈α
 and␈α his␈α
opponent␈αthe␈α
minimizing␈αplayer.␈α
Usually,␈αthe␈α
numerical␈αvalues
␈↓ ↓H␈↓arise,␈α
because␈α
the␈α
search␈α
cannot␈α
be␈α
carried␈α
 out␈α
to␈α
the␈α
end␈α
of␈α
the␈α
game,␈α
and␈α
the␈α
analysis␈α
stops␈α
with
␈↓ ↓H␈↓reasonably␈α⊃static␈α⊃positions␈α⊃that␈α⊂ can␈α⊃ be␈α⊃ evaluated␈α⊃ by␈α⊂ some␈α⊃ rule.␈α⊃  Naturally,␈α⊃ the␈α⊂function
␈↓ ↓H␈↓␈↓↓imval␈↓␈α∂ is␈α∞ chosen␈α∂ to␈α∞ be␈α∂ easy␈α∞ to␈α∂ calculate␈α∂and␈α∞to␈α∂correlate␈α∞well␈α∂with␈α∞the␈α∂probability␈α∂that␈α∞the
␈↓ ↓H␈↓maximizing  player  can win the position.

␈↓ ↓H␈↓        The␈αsimplest␈α
rule␈αfor␈α
finding␈αthe␈αcorrect␈α
move␈αin␈α
a␈αposition␈α
uses␈αauxiliary␈αfunctions␈α
␈↓↓valmax␈↓
␈↓ ↓H␈↓and␈α
␈↓↓valmin␈↓␈αthat␈α
give␈αa␈α
value␈αto␈α
a␈α
position␈αby␈α
using␈α␈↓↓imval␈↓␈α
if␈αthe␈α
position␈αis␈α
terminal␈α
and␈αtaking
␈↓ ↓H␈↓the max or min of the successor positions otherwise.

␈↓ ↓H␈↓        For␈α
this␈α
we␈α
want␈α
functions␈α
for␈α
getting␈α
the␈α
maximum␈α
or␈α
the␈α
minimum␈α
of␈α
a␈α
function␈α
on␈α
a␈α
list,
␈↓ ↓H␈↓and they are defined as follows:

␈↓ ↓H␈↓␈↓ β=␈↓↓maxlis[u, f] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ -∞ ␈↓αelse␈↓↓ max[f[␈↓αa␈↓↓␈α∧u], maxlis[␈↓αd␈↓↓␈α∧u, f]]␈↓, 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ βL␈↓↓minlis[u, f] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ ∞ ␈↓αelse␈↓↓ min[f[␈↓αa␈↓↓␈α∧u], minlis[␈↓αd␈↓↓␈α∧u, f]]␈↓. 

␈↓ ↓H␈↓In␈αthese␈αfunctions,␈α
-∞␈αand␈α∞␈α
represent␈αnumbers␈αthat␈α
are␈αsmaller␈αand␈α
larger␈αthan␈αany␈αactual␈α
values
␈↓ ↓H␈↓that␈α
will␈αoccur␈α
in␈αevaluating␈α
␈↓↓f.␈α
If␈↓␈αthese␈α
numbers␈αare␈α
not␈α
available,␈αthen␈α
it␈αis␈α
necessary␈α
to␈αprime
␈↓ ↓H␈↓the␈α∞function␈α∞with␈α∞the␈α∞values␈α∞of␈α∞␈↓↓f␈↓␈α∞applied␈α∞to␈α∞the␈α∞first␈α∞element␈α∞of␈α∞the␈α∞list,␈α∞and␈α∞the␈α∞functions␈α∞are
␈↓ ↓H␈↓meaningless␈αfor␈αnull␈αlists.␈α Iterative␈α
versions␈αof␈αthe␈αfunctions␈αare␈α
generally␈αbetter;␈αwe␈αgive␈αonly␈α
the
␈↓ ↓H␈↓iterative version of ␈↓↓maxlis,␈↓ namely

␈↓ ↓H␈↓␈↓ ∧m␈↓↓maxlis[u, f] ← maxlisa[u, -∞, f]␈↓, 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ β∞␈↓↓maxlisa[u, x, f] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ maxlisa[␈↓αd␈↓↓␈α∧u, max[x, f[␈↓αa␈↓↓␈α∧u]], f]␈↓. 

␈↓ ↓H␈↓We now have

␈↓ ↓H␈↓␈↓ β⊗␈↓↓valmax p ← ␈↓αif␈↓↓ ter p ␈↓αthen␈↓↓ imval p ␈↓αelse␈↓↓ maxlis[successors p, valmin]␈↓, 
␈↓ ↓H␈↓34␈↓ ¬jCHAPTER II␈↓ H


␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ β_␈↓↓valmin p ← ␈↓αif␈↓↓ ter p ␈↓αthen␈↓↓ imval p ␈↓αelse␈↓↓ minlis[successors p, valmax]␈↓. 

␈↓ ↓H␈↓The best move is now chosen by

␈↓ ↓H␈↓␈↓ ∧3␈↓↓movemax p ← bestmax[succesors p, valmin]␈↓, 

␈↓ ↓H␈↓or

␈↓ ↓H␈↓␈↓ ∧5␈↓↓movemin p ← bestmin[succesors p, valmax]␈↓, 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ ∧)␈↓↓bestmax[u, f] ← bestmaxa[␈↓αd␈↓↓␈α∧u, ␈↓αa␈↓↓␈α∧u, f[␈↓αa␈↓↓␈α∧u], f]␈↓, 

␈↓ ↓H␈↓                ␈↓↓bestmaxa[u, sofar, bestsofar, f] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ sofar␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ f[␈↓αa␈↓↓␈α∧u] ≤ bestsofar ␈↓αthen␈↓↓ bestmaxa[␈↓αd␈↓↓␈α∧u, sofar, bestsofar, f]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ bestmaxa[␈↓αd␈↓↓␈α∧u, ␈↓αa␈↓↓␈α∧u, f[␈↓αa␈↓↓␈α∧u], f]␈↓,

␈↓ ↓H␈↓␈↓ ∧-␈↓↓bestmin[u, f] ← bestmina[␈↓αd␈↓↓␈α∧u, ␈↓αa␈↓↓␈α∧u, f[␈↓αa␈↓↓␈α∧u], f]␈↓, 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓                ␈↓↓bestmina[u, sofar, bestsofar, f] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ sofar␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ f[␈↓αa␈↓↓␈α∧u] ≥ bestsofar ␈↓αthen␈↓↓ bestmina[␈↓αd␈↓↓␈α∧u, sofar, bestsofar, f]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ bestmina[␈↓αd␈↓↓␈α∧u, ␈↓αa␈↓↓␈α∧u, f[␈↓αa␈↓↓␈α∧u], f]␈↓.

␈↓ ↓H␈↓        However,␈α
this␈αstraight␈α
minimax␈α
computation␈αof␈α
the␈α
best␈αmove␈α
does␈α
much␈αmore␈α
computation
␈↓ ↓H␈↓in␈α⊂general␈α⊃than␈α⊂is␈α⊃usually␈α⊂necessary.␈α⊃ The␈α⊂simplest␈α⊃way␈α⊂to␈α⊃see␈α⊂this␈α⊃is␈α⊂from␈α⊃the␈α⊂move␈α⊃tree␈α⊂of
␈↓ ↓H␈↓figure 5.
␈↓ ↓H␈↓␈↓ ¬jCHAPTER II␈↓ *35





␈↓"␈↓ ↓H␈↓␈↓ εX8
␈↓"␈↓ ↓H␈↓␈↓ ¬xmax␈↓ ε(≤'
␈↓"␈↓ ↓H␈↓␈↓ ελ≤'␈↓ ε_≥␈↓ ε_ααα 1
␈↓"␈↓ ↓H␈↓␈↓ ¬8min␈↓ ¬h≤'␈↓ ε(`≥
␈↓"␈↓ ↓H␈↓␈↓ ¬H≤'␈↓ εX6
␈↓"␈↓ ↓H␈↓␈↓ ¬8'␈↓ ¬8≥
␈↓"␈↓ ↓H␈↓␈↓ ¬H`≥␈↓ εX9
␈↓"␈↓ ↓H␈↓␈↓ ¬h`≥␈↓ ε(≤'
␈↓"␈↓ ↓H␈↓␈↓ ελ`≥␈↓ ε_'␈↓ ε_ααα x
␈↓"␈↓ ↓H␈↓␈↓ ε(`≥
␈↓"␈↓ ↓H␈↓␈↓ εXx


␈↓"␈↓ ↓H␈↓␈↓ ¬HFigure 5.


␈↓ ↓H␈↓We␈α∞see␈α∞from␈α∂this␈α∞figure␈α∞that␈α∞it␈α∂is␈α∞unnecessary␈α∞to␈α∞examine␈α∂the␈α∞moves␈α∞marked␈α∞ ␈↓x␈↓ ␈α∂because␈α∞their
␈↓ ↓H␈↓values␈αhave␈αno␈αeffect␈αon␈α
the␈αvalue␈αof␈αthe␈αgame␈α
or␈αon␈αthe␈αcorrect␈αmove␈α
since␈αthe␈αpresence␈αof␈αthe␈α
9
␈↓ ↓H␈↓is␈α∞sufficient␈α∞information␈α
at␈α∞this␈α∞point␈α
to␈α∞show␈α∞that␈α
the␈α∞move␈α∞leading␈α
to␈α∞the␈α∞vertex␈α∞preceding␈α
it
␈↓ ↓H␈↓should not be chosen by the minimizing player.

␈↓ ↓H␈↓        The␈α
general␈α
situation␈α
is␈α
that␈α
it␈α
is␈αunnecessary␈α
to␈α
examine␈α
further␈α
moves␈α
in␈α
a␈α
position␈αonce␈α
a
␈↓ ↓H␈↓move␈α
is␈α
found␈α
that␈α
refutes␈α∞moving␈α
to␈α
the␈α
position␈α
in␈α
the␈α∞first␈α
place.␈α
 This␈α
idea␈α
is␈α
called␈α∞the␈α
β-
␈↓ ↓H␈↓heuristic and expressed in the following recursive definitions:

␈↓ ↓H␈↓        ␈↓↓maxval p ← maxval1[p, -∞, ∞]␈↓,

␈↓ ↓H␈↓        ␈↓↓maxval1[p, α, β] ← ␈↓αif␈↓↓ ter p ␈↓αthen␈↓↓ max[α, min[β, imval p]] ␈↓
␈↓ ↓H␈↓                                  ␈↓↓␈↓αelse␈↓↓ maxval2[successors p, α, β]␈↓,

␈↓ ↓H␈↓        ␈↓↓maxval2[u, α, β] ← {minval1[␈↓αa␈↓↓␈α∧u, α, β]}  [λw: ␈↓αif␈↓↓ w = β ␈↓αthen␈↓↓ β ␈↓αelse␈↓↓ maxval2[␈↓αd␈↓↓␈α∧u, w, β]]␈↓,

␈↓ ↓H␈↓        ␈↓↓minval p ← minval1[p, -∞, ∞]␈↓,

␈↓ ↓H␈↓        ␈↓↓minval1[p, α, β] ← ␈↓αif␈↓↓ ter p ␈↓αthen␈↓↓ max[α, min[β, imval p]] ␈↓
␈↓ ↓H␈↓                                  ␈↓↓␈↓αelse␈↓↓ minval2[successors p, α, β]␈↓,

␈↓ ↓H␈↓        ␈↓↓minval2[u, α, β] ← {maxval1[␈↓αa␈↓↓␈α∧u, α, β]} [λw: ␈↓αif␈↓↓ w = α ␈↓αthen␈↓↓ α ␈↓αelse␈↓↓ minval2[␈↓αd␈↓↓␈α∧u, α, w]␈↓.

␈↓ ↓H␈↓        The␈αreduction␈αin␈αnumber␈αof␈αpositions␈αexamined␈αgiven␈αby␈αthe␈ααβ␈αalgorithm␈αover␈αthe␈αsimple
␈↓ ↓H␈↓minimax␈α
algorithm␈α
depends␈α
on␈α
the␈α
order␈α
in␈α
which␈α
the␈α
moves␈α
are␈α
examined.␈α
 In␈α
the␈α∞worst␈α
case,
␈↓ ↓H␈↓the␈αmoves␈αhappen␈αto␈αbe␈αexamined␈αin␈αinverse␈αorder␈αof␈αmerit␈αin␈αevery␈αposition␈αon␈αthe␈αtree,␈αi.e.␈αthe
␈↓ ↓H␈↓worst␈αmove␈αfirst.␈α In␈αthat␈αcase,␈αthere␈αis␈αno␈αimprovement␈αover␈αminimax.␈α The␈αbest␈αcase␈αis␈αthe␈αone
␈↓ ↓H␈↓36␈↓ ¬jCHAPTER II␈↓ H


␈↓ ↓H␈↓in␈α
which␈α
the␈α
best␈α
move␈α
in␈α
every␈α
position␈α
is␈α
examined␈α
first.␈α
 If␈α
we␈α
look␈α
␈↓↓n␈↓␈α
moves␈α
deep␈α
on␈α
a␈αtree
␈↓ ↓H␈↓that␈αhas␈α␈↓↓k␈↓␈αsuccessors␈αto␈αeach␈αposition,␈αthen␈αminimax␈αlooks␈αat␈α␈↓↓k␈↓∧n␈↓␈αpositions␈αwhile␈ααβ␈αlooks␈αat␈αabout
␈↓ ↓H␈↓only␈α∂␈↓↓k␈↓∧n/2␈↓.␈α∂ Thus␈α∂a␈α⊂program␈α∂that␈α∂looks␈α∂at␈α⊂10␈↓∧4␈↓␈α∂moves␈α∂with␈α∂αβ␈α∂might␈α⊂have␈α∂to␈α∂look␈α∂at␈α⊂10␈↓∧8␈↓␈α∂with
␈↓ ↓H␈↓minimax.␈α For␈αthis␈αreason,␈αgame␈αplaying␈αprograms␈αusing␈ααβ␈αmake␈αa␈αbig␈αeffort␈αto␈αinclude␈αas␈αgood
␈↓ ↓H␈↓as␈α
possible␈αan␈α
ordering␈αof␈α
moves␈αinto␈α
the␈α␈↓↓successors␈↓␈α
function.␈α When␈α
there␈αis␈α
a␈αdeep␈α
tree␈αsearch␈α
to
␈↓ ↓H␈↓be␈αdone,␈αthe␈αway␈αto␈αmake␈αthe␈αordering␈αis␈αwith␈αa␈αshort␈αlook-ahead␈αto␈αa␈αmuch␈αsmaller␈αdepth␈αthan
␈↓ ↓H␈↓the␈α⊂main␈α∂search.␈α⊂ Still␈α⊂shorter␈α∂look-aheads␈α⊂are␈α∂used␈α⊂deeper␈α⊂in␈α∂the␈α⊂tree,␈α∂and␈α⊂beyond␈α⊂a␈α∂certain
␈↓ ↓H␈↓depth, non-look-ahead ordering methods are of decreasing complexity.

␈↓ ↓H␈↓        A␈α
version␈α
of␈α
αβ␈α
incorporating␈α∞optimistic␈α
and␈α
pessimistic␈α
evaluations␈α
of␈α
positions␈α∞was␈α
first
␈↓ ↓H␈↓proposed␈α∂by␈α∂McCarthy␈α∂about␈α∂1958.␈α∂ Edwards␈α∂and␈α∂Hart␈α∂at␈α∂M.I.T.␈α∂about␈α∂1959␈α∂proved␈α∂that␈α∞the
␈↓ ↓H␈↓present␈α∞version␈α∞of␈α∞αβ␈α∂works␈α∞and␈α∞calculated␈α∞the␈α∞improvement␈α∂it␈α∞gives␈α∞over␈α∞minimax.␈α∂ The␈α∞first
␈↓ ↓H␈↓publication,␈α∞however,␈α∞was␈α
Brudno␈α∞(1963).␈α∞ It␈α
is␈α∞worth␈α∞noting␈α
that␈α∞αβ␈α∞was␈α
not␈α∞used␈α∞in␈α∞the␈α
early
␈↓ ↓H␈↓chess␈αplaying␈αprograms␈αin␈αspite␈αof␈αthe␈αfact␈αthat␈αit␈αis␈αclearly␈αused␈αin␈αany␈αhuman␈αplay.␈α Its␈αnon-use,
␈↓ ↓H␈↓therefore,␈α∩represents␈α∩a␈α⊃failure␈α∩of␈α∩self-observation.␈α⊃ Very␈α∩likely,␈α∩there␈α⊃are␈α∩a␈α∩number␈α∩of␈α⊃other
␈↓ ↓H␈↓algorithms␈α
used␈α
in␈αhuman␈α
thought␈α
that␈α
we␈αhave␈α
not␈α
noticed␈αand␈α
incorporated␈α
in␈α
our␈αprograms.
␈↓ ↓H␈↓To␈αthe␈αextent␈αthat␈αthis␈αis␈αso,␈αartificial␈αintelligence␈αwill␈αbe␈α␈↓↓a␈αposteriori␈↓␈αobvious␈αeven␈αthough␈αit␈αis␈α␈↓↓a
␈↓ ↓H␈↓↓priori␈↓ very difficult.
␈↓ ↓H␈↓␈↓ εH␈↓ *37


␈↓ ↓H␈↓α␈↓ ¬zChapter III

␈↓ ↓H␈↓α␈↓ ∧(PROVING LISP PROGRAMS CORRECT


␈↓ ↓H␈↓        The␈αtheory␈αof␈αcomputation␈α
may␈αbe␈αdivided␈αinto␈αtwo␈α
parts.␈α The␈αfirst␈αis␈αthe␈α
general␈αtheory
␈↓ ↓H␈↓of␈α
computability␈α
including␈α
topics␈α
like␈α
universal␈α
functions,␈α
the␈α
existence␈α
of␈αuncomputable␈α
functions,
␈↓ ↓H␈↓lambda␈α∪calculus,␈α∪call-by-name␈α∪and␈α∪call-by-value,␈α∪and␈α∪the␈α∪relation␈α∪of␈α∪conditional␈α∩expression
␈↓ ↓H␈↓recursion␈α∞to␈α∞other␈α∞formalisms␈α∞for␈α∂describing␈α∞computable␈α∞functions.␈α∞ The␈α∞second␈α∞part,␈α∂which␈α∞we
␈↓ ↓H␈↓will␈α∂discuss␈α∞in␈α∂this␈α∞chapter␈α∂emphasizes␈α∞techniques␈α∂for␈α∞proving␈α∂particular␈α∞facts␈α∂about␈α∞particular
␈↓ ↓H␈↓computable␈α∂functions.␈α⊂ We␈α∂emphasize␈α∂the␈α⊂use␈α∂of␈α∂the␈α⊂techniques␈α∂more␈α∂than␈α⊂their␈α∂mathematical
␈↓ ↓H␈↓background.␈α Much␈αof␈αthe␈αmaterial␈αin␈αthis␈αchapter␈αis␈αbased␈αon␈α(Cartwright␈α1977)␈αand␈αthe␈αrest␈αon
␈↓ ↓H␈↓(McCarthy 1977).

␈↓ ↓H␈↓        We␈αshall␈αconfine␈αourselves␈αto␈αproving␈α␈↓↓extensional␈↓␈α␈↓↓properties␈↓␈αof␈α␈↓↓clean,␈↓␈α␈↓↓pure␈↓␈αLISP␈α
programs.
␈↓ ↓H␈↓An␈α⊂␈↓↓extensional␈↓␈α⊂␈↓↓property␈↓␈α⊂is␈α⊃one␈α⊂that␈α⊂depends␈α⊂only␈α⊂on␈α⊃the␈α⊂function␈α⊂computed␈α⊂by␈α⊃the␈α⊂program.
␈↓ ↓H␈↓Thus␈α∞it␈α∞includes␈α∞the␈α∞fact␈α∂that␈α∞two␈α∞sort␈α∞programs␈α∞compute␈α∂the␈α∞same␈α∞function␈α∞or␈α∞that␈α∂␈↓↓append␈↓␈α∞is
␈↓ ↓H␈↓associative␈αbut␈αdoes␈αnot␈αinclude␈αthe␈αfact␈αthat␈αone␈αsort␈αprogram␈αdoes␈α␈↓↓n␈↓∧2␈↓↓␈↓␈αcomparisons␈αand␈αanother
␈↓ ↓H␈↓␈↓↓n log n␈↓␈α
comparisons.␈α
 ␈↓↓Clean␈↓␈α
LISP␈α
programs␈α
have␈α
no␈α
side␈α
effects␈α
(our␈α
methods␈α
require␈αthe␈α
freedom
␈↓ ↓H␈↓to␈α
replace␈αa␈α
subexpression␈αby␈α
an␈αequal␈α
expression),␈αand␈α
equality␈αrefers␈α
to␈αthe␈α
S-expressions␈αand
␈↓ ↓H␈↓not␈αto␈αthe␈αlist␈αstructures.␈α ␈↓↓Pure␈↓␈αLISP␈αinvolves␈αonly␈αrecursive␈αfunction␈αdefinitions␈αand␈α
doesn't␈αuse
␈↓ ↓H␈↓assignment␈αstatements.␈α
 It␈αwouldn't␈α
be␈αdifficult␈α
to␈αgive␈α
corresponding␈αmethods␈α
that␈αwould␈αbe␈α
valid
␈↓ ↓H␈↓for non-functional programs, because this topic is well developed.

␈↓ ↓H␈↓        In␈α⊂spite␈α⊂of␈α∂all␈α⊂these␈α⊂limitations,␈α⊂the␈α∂techniques␈α⊂are␈α⊂useful␈α⊂and␈α∂point␈α⊂the␈α⊂way␈α⊂to␈α∂further
␈↓ ↓H␈↓progress.␈α∞ The␈α∞main␈α∞idea␈α∂is␈α∞to␈α∞represent␈α∞the␈α∞programs␈α∂formally␈α∞using␈α∞first␈α∞order␈α∂logic.␈α∞ Higher
␈↓ ↓H␈↓order␈α∞functionals␈α∂and␈α∞predicates␈α∞are␈α∂used␈α∞informally.␈α∞ Formal␈α∂proofs␈α∞of␈α∞properties␈α∂of␈α∞programs
␈↓ ↓H␈↓can␈α∃easily␈α⊗be␈α∃checked␈α⊗using␈α∃an␈α⊗automatic␈α∃proof␈α⊗checker␈α∃such␈α⊗as␈α∃FOL␈α⊗(Weyrauch␈α∃1977).
␈↓ ↓H␈↓Examples are given in Appendix II.

␈↓ ↓H␈↓        We␈αbegin␈αwith␈αan␈αinformal␈αsample␈αproof,␈αcommenting␈αabout␈αthe␈αinformation␈α
and␈αconcepts
␈↓ ↓H␈↓needed␈αto␈αmake␈αthe␈αproof␈αwork.␈α We␈αthen␈αproceed␈αto␈αformalize␈αthese␈αideas.␈α The␈α necessary␈αbasic
␈↓ ↓H␈↓facts␈αcan␈αbe␈αdivided␈αinto␈αseveral␈αcategories:␈αfirst␈αorder␈αlogic␈αincluding␈αconditional␈αforms␈αand␈αfirst
␈↓ ↓H␈↓order␈αlambda-expressions,␈αalgebraic␈αfacts␈αabout␈αlists␈αand␈αS-expressions,␈αfacts␈αabout␈αthe␈αinductive
␈↓ ↓H␈↓structure of lists and S-expressions, and general facts about functions defined by recursion.



␈↓ ↓H␈↓1.  ␈↓αIntroductory Example.␈↓


␈↓ ↓H␈↓        Consider the function ␈↓↓append␈↓ ( * ) defined by

␈↓ ↓H␈↓␈↓ ∧M␈↓↓u * v ← if ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ v ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧u . [␈↓αd␈↓↓␈α∧u * v]␈↓ 

␈↓ ↓H␈↓and the predicate ␈↓↓member␈↓ ( ε ) defined by

␈↓ ↓H␈↓␈↓ ∧R␈↓↓x ε u ← ¬␈↓αn␈↓↓␈α∧u ∧ [x = ␈↓αa␈↓↓␈α∧u ∨ x ε ␈↓αd␈↓↓␈α∧u]        ␈↓ 
␈↓ ↓H␈↓38␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓where␈α
␈↓↓x␈↓␈α
is␈α
any␈α
S-expression␈α
and␈α
␈↓↓u␈↓␈α
and␈α
␈↓↓v␈↓␈α
are␈α
lists␈α
(whose␈α
elements␈α
are␈α
S-expresssions).␈α
  (Note␈α
that
␈↓ ↓H␈↓our␈αprecedence␈αconventions␈αimply␈αthat␈α ␈↓↓␈↓αd␈↓↓␈α∧u * v = [␈↓αd␈↓↓␈α∧u] * v␈↓.)␈α  It␈αis␈αprobably␈αintuitively␈αclear␈αthat␈αif
␈↓ ↓H␈↓␈↓↓x␈↓␈α
is␈αa␈α
member␈αof␈α
one␈αof␈α
the␈αlists␈α
␈↓↓u␈↓␈αor␈α
␈↓↓v␈↓␈α
then␈α␈↓↓x␈↓␈α
is␈αa␈α
member␈αof␈α
the␈αlist␈α
␈↓↓u * v␈↓.␈α  We␈α
will␈α
give␈αan
␈↓ ↓H␈↓informal proof of this property.

␈↓ ↓H␈↓        The␈α∂proof␈α∞will␈α∂be␈α∞based␈α∂on␈α∂the␈α∞principle␈α∂of␈α∞␈↓↓list induction␈↓␈α∂which␈α∞is␈α∂analogous␈α∂to␈α∞natural
␈↓ ↓H␈↓induction␈α∂(for␈α⊂functions␈α∂on␈α∂the␈α⊂natural␈α∂numbers).␈α⊂ This␈α∂principle␈α∂states␈α⊂that␈α∂if␈α⊂some␈α∂property,
␈↓ ↓H␈↓␈↓	F␈↓(␈↓¬NIL␈↓),␈αholds␈αfor␈αthe␈αlist␈α␈↓¬NIL␈↓␈αand␈αif,␈αby␈αassuming␈α␈↓	F␈↓(␈↓↓u␈↓)␈αholds␈αfor␈α␈↓↓␈↓αd␈↓↓␈α∧u␈↓,␈αwe␈αcan␈αprove␈αthat␈αit␈αholds␈αfor
␈↓ ↓H␈↓the list ␈↓↓u␈↓ then ␈↓	F␈↓(␈↓↓u␈↓) holds for all lists ␈↓↓u.␈↓   In our case ␈↓	F␈↓(␈↓↓u␈↓) is the property:

␈↓ ↓H␈↓␈↓ ∧G␈↓↓[x ε u ∨ x ε v] ⊃ x ε [u * v] .              ␈↓ 

␈↓ ↓H␈↓The␈αinduction␈αwill␈αbe␈αwith␈αrespect␈αto␈αthe␈αlist␈α␈↓↓u,␈↓␈αeg.␈αthe␈αfirst␈αargument␈αto␈α␈↓↓append.␈↓␈α The␈αvariables
␈↓ ↓H␈↓␈↓↓x␈↓ and ␈↓↓v␈↓ are just carried along.

␈↓ ↓H␈↓        The␈αproof␈α
consists␈αof␈αtwo␈α
parts.␈α First␈αwe␈α
assume␈α␈↓αn␈↓␈α∧␈↓↓u.␈↓␈α Then␈α
by␈αthe␈αdefinition␈α
of␈α␈↓↓member,␈↓
␈↓ ↓H␈↓␈↓↓x ε u␈↓ is false and by the definition of ␈↓↓append,␈↓ ␈↓↓u * v = v␈↓.  Thus ␈↓	F␈↓(␈↓↓u␈↓) becomes

␈↓ ↓H␈↓␈↓ ¬Q␈↓↓x ε v ⊃ x ε v        ␈↓ 

␈↓ ↓H␈↓which is true.

␈↓ ↓H␈↓        Next we assume ¬␈↓αn␈↓␈α∧␈↓↓u␈↓ and that ␈↓↓␈↓	F␈↓↓(␈↓αd␈↓↓␈α∧u)␈↓ is true.  Thus

␈↓ ↓H␈↓␈↓ ¬λ␈↓↓[x ε ␈↓αd␈↓↓␈α∧u ∨ x ε v] ⊃ x ε [␈↓αd␈↓↓␈α∧u * v]␈↓ 

␈↓ ↓H␈↓By␈α∞definition␈α
of␈α∞␈↓↓append,␈↓␈α
␈↓↓u * v␈↓␈α∞reduces␈α
to␈α∞␈↓↓␈↓αa␈↓↓␈α∧u␈α
.␈α∞[␈↓αd␈↓↓␈α∧u␈α
*␈α∞v]␈↓.␈α
 Thus␈α∞␈↓↓u * v ≠ ␈↓¬NIL␈↓↓␈↓,␈α∞␈↓↓␈↓αa␈↓↓␈α∧[u * v] = ␈↓αa␈↓↓␈α∧u␈↓␈α
and
␈↓ ↓H␈↓␈↓↓␈↓αd␈↓↓␈α∧[u * v] = ␈↓αd␈↓↓␈α∧u * v␈↓.␈α By␈αdefinition␈αof␈α
␈↓↓member,␈↓␈α␈↓↓x ε u␈↓␈αreduces␈αto␈α
␈↓↓x = ␈↓αa␈↓↓␈α∧u ∨ x ε ␈↓αd␈↓↓␈α∧u␈↓.␈α So␈αwe␈αconsider␈α
two
␈↓ ↓H␈↓cases: ␈↓↓x = ␈↓αa␈↓↓␈α∧u␈↓  and  ␈↓↓x ε ␈↓αd␈↓↓␈α∧u ∨ x ε v␈↓.

␈↓ ↓H␈↓        In␈αthe␈αfirst␈αcase␈αwe␈αhave␈α␈↓↓x = ␈↓αa␈↓↓␈α∧[u * v]␈↓␈αand␈αso,␈αby␈αdefinition␈αof␈α␈↓↓member,␈↓␈α␈↓↓x ε [u * v]␈↓␈αand␈α␈↓	F␈↓(␈↓↓u␈↓)
␈↓ ↓H␈↓is␈α
true.␈α
 In␈α
the␈α
second␈α
case␈α
we␈α
have␈αby␈α
the␈α
induction␈α
hypothesis␈α
that␈α
␈↓↓x ε [␈↓αd␈↓↓␈α∧u * v]␈↓␈α
and␈α
again,␈αby
␈↓ ↓H␈↓definition of ␈↓↓member,␈↓  ␈↓	F␈↓(␈↓↓u␈↓) holds.

␈↓ ↓H␈↓        Thus␈α
we␈αhave␈α
done␈α
the␈αrequired␈α
proofs␈αand␈α
by␈α
list␈αinduction␈α
the␈αproperty␈α
␈↓	F␈↓(␈↓↓u␈↓)␈α
holds␈αfor
␈↓ ↓H␈↓any list ␈↓↓u.␈↓

␈↓ ↓H␈↓        In carrying out the proof we have used properties of lists such as

␈↓ ↓H␈↓                                ␈↓↓[x . u]␈↓ is a list
␈↓ ↓H␈↓                                ␈↓↓␈↓αa␈↓↓␈α∧[x . u] = x]␈↓
␈↓ ↓H␈↓                                ␈↓↓␈↓αd␈↓↓␈α∧[x . u] = u]␈↓
␈↓ ↓H␈↓                                ␈↓↓¬␈↓αn␈↓↓␈α∧[x . u]␈↓

␈↓ ↓H␈↓for␈α
any␈α
S-expression␈α
␈↓↓x␈↓␈α∞and␈α
any␈α
list␈α
␈↓↓u.␈↓␈α∞ We␈α
have␈α
also␈α
used␈α∞these␈α
properties␈α
with␈α
␈↓↓u␈↓␈α∞replaced␈α
by
␈↓ ↓H␈↓␈↓↓u * v␈↓␈αor␈α␈↓↓␈↓αd␈↓↓␈α∧u * v␈↓.␈α To␈αdo␈αthis␈αwe␈αneed␈αto␈αknow␈αthat␈α␈↓↓u * v␈↓␈αis␈αa␈αlist␈αor␈αthat␈α␈↓↓␈↓αd␈↓↓␈α∧u * v␈↓␈αis␈αa␈αlist.␈α This␈αis
␈↓ ↓H␈↓essentially␈α⊂the␈α⊂same␈α⊂as␈α⊃saying␈α⊂that␈α⊂the␈α⊂computation␈α⊂defined␈α⊃by␈α⊂␈↓↓append␈↓␈α⊂terminates␈α⊂in␈α⊃a␈α⊂finite
␈↓ ↓H␈↓number of steps or that ␈↓↓append␈↓ is a total function.
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *39


␈↓ ↓H␈↓        Saying␈α
that␈α␈↓↓u␈α
*␈α
v␈↓␈αreduces␈α
to␈α
␈↓↓␈↓αa␈↓↓␈α∧u␈α.␈α
[␈↓αd␈↓↓␈α∧u␈α*␈α
v]␈↓␈α
is␈αbased␈α
on␈α
the␈αrule␈α
for␈α
computing␈αrecursively
␈↓ ↓H␈↓defined␈α∂functions.␈α∂  It␈α∂too,␈α∂is␈α∂only␈α∂meaningful␈α⊂when␈α∂␈↓↓␈↓αd␈↓↓␈α∧u * v␈↓␈α∂is␈α∂a␈α∂list,␈α∂eg.␈α∂when␈α∂␈↓↓append␈↓␈α⊂is␈α∂total.
␈↓ ↓H␈↓Note␈αthat␈αin␈αusing␈αthe␈αrecursive␈αfunction␈α
definition␈αand␈αthe␈αrule␈αfor␈αcomptation␈αwe␈αare␈α
essentially
␈↓ ↓H␈↓substituting␈α∪equals␈α∩for␈α∪equals␈α∪in␈α∩the␈α∪problem.␈α∪ The␈α∩two␈α∪cases␈α∪can␈α∩be␈α∪combined␈α∪giving␈α∩the
␈↓ ↓H␈↓␈↓↓functional equation␈↓ for ␈↓↓append␈↓

␈↓ ↓H␈↓␈↓ ∧F␈↓↓u * v = ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ v ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧u . [␈↓αd␈↓↓␈α∧u * v].␈↓ 

␈↓ ↓H␈↓Again, being  able to use the functional equation here depends on knowing ␈↓↓append␈↓ is total.

␈↓ ↓H␈↓        Similiarly␈α
several␈α
of␈αthe␈α
statements␈α
made␈α
about␈α␈↓↓member␈↓␈α
depend␈α
on␈α
the␈αfact␈α
that␈α
it␈α
is␈αtotal.
␈↓ ↓H␈↓Thus␈α
to␈α
complete␈α
the␈α
proof␈α
it␈α
is␈α
necessary␈α
to␈α
know␈α
that␈α
␈↓↓append␈↓␈α
and␈α
␈↓↓member␈↓␈α
are␈α
total.␈α
 This␈α
should
␈↓ ↓H␈↓be␈α⊂intuitively␈α⊂clear,␈α⊂since␈α⊂the␈α⊂recursive␈α⊂calls␈α⊂in␈α⊂the␈α⊂definitions␈α⊂ depend␈α⊂on␈α⊂the␈α⊂␈↓↓cdr␈↓␈α⊂of␈α⊂the␈α∂test
␈↓ ↓H␈↓variable␈α∩and,␈α∩since␈α⊃our␈α∩lists␈α∩are␈α∩finite,␈α⊃this␈α∩will␈α∩eventually␈α∩be␈α⊃␈↓¬NIL␈↓␈α∩and␈α∩the␈α∩computation␈α⊃will
␈↓ ↓H␈↓terminate.  We will see later how to state and prove such facts.

␈↓ ↓H␈↓        The␈αvalidity␈αof␈αthe␈αlist␈αinduction␈αprinciple␈αis␈αdue␈αto␈αthe␈αfact␈αthat␈αwe␈αrequire␈αour␈αlists␈αto␈αbe
␈↓ ↓H␈↓finite.␈α This␈αjust␈αis␈αone␈αof␈αmany␈αforms␈αof␈αinduction.␈α We␈αwill␈αsee␈αexamples␈αof␈αother␈αforms␈αas␈αwell
␈↓ ↓H␈↓as␈αother␈αapplications␈αof␈αlist␈αinduction.␈α Looking␈α
at␈αinduction␈αin␈αanother␈αway,␈αif␈αone␈αstarts␈α
with␈αa
␈↓ ↓H␈↓set␈α∞of␈α∞properties␈α∞that␈α∞must␈α∞be␈α∞satisfied␈α∞by␈α∞a␈α∞domain␈α∞and␈α∞some␈α∞basic␈α∞functions␈α∞on␈α∞that␈α
domain,
␈↓ ↓H␈↓then␈α∂requiring␈α∂that␈α∂some␈α∂induction␈α∂principle␈α∂be␈α∞valid␈α∂ is␈α∂a␈α∂way␈α∂of␈α∂giving␈α∂further␈α∞information
␈↓ ↓H␈↓about the domain.



␈↓ ↓H␈↓2.  ␈↓αFirst Order Logic with Conditional Forms and Lambda-expressions.␈↓


␈↓ ↓H␈↓        The␈α∂logic␈α∂we␈α∂shall␈α∂use␈α∂is␈α∂called␈α∂first␈α∂order␈α∂logic␈α∂with␈α∂equality,␈α∂but␈α∂we␈α∂will␈α∂extend␈α⊂it␈α∂by
␈↓ ↓H␈↓admitting␈α⊂conditional␈α⊃forms␈α⊂as␈α⊂terms␈α⊃and␈α⊂first␈α⊂order␈α⊃lambda-expressions␈α⊂as␈α⊃function␈α⊂symbols.
␈↓ ↓H␈↓These␈αextensions␈αdo␈αnot␈αchange␈αthe␈αlogical␈αstrength␈αof␈αthe␈αtheory,␈αbecause,␈αas␈αwe␈αshall␈αsee,␈αevery
␈↓ ↓H␈↓sentence␈α∩that␈α∩includes␈α∩conditional␈α∪forms␈α∩or␈α∩first␈α∩order␈α∪lambdas␈α∩can␈α∩be␈α∩transformed␈α∪into␈α∩an
␈↓ ↓H␈↓equivalent␈α
sentence␈α
without␈α
them.␈α
 However,␈αthe␈α
extensions␈α
are␈α
practically␈α
important,␈αbecause␈α
they
␈↓ ↓H␈↓permit us to use recursive definitions directly as formulas of the logic.

␈↓ ↓H␈↓        Formulas␈α∞of␈α∞the␈α∞logic␈α∞are␈α∞built␈α∞from␈α∞constants,␈α∞variables,␈α∞predicate␈α∞symbols,␈α∂and␈α∞function
␈↓ ↓H␈↓symbols␈α⊂using␈α⊂function␈α∂application,␈α⊂conditional␈α⊂forms,␈α∂boolean␈α⊂forms,␈α⊂lambda␈α⊂expressions,␈α∂and
␈↓ ↓H␈↓quantifiers.

␈↓ ↓H␈↓␈↓αConstants␈↓:␈α∞We␈α
will␈α∞use␈α∞S-expresssions␈α
as␈α∞constants␈α
standing␈α∞for␈α∞themselves␈α
and␈α∞also␈α∞lower␈α
case
␈↓ ↓H␈↓letters␈α∩from␈α∩the␈α∩first␈α∩part␈α∩of␈α∩the␈α∪alphabet␈α∩to␈α∩represent␈α∩constants␈α∩in␈α∩other␈α∩domains␈α∪than␈α∩S-
␈↓ ↓H␈↓expressions.

␈↓ ↓H␈↓␈↓αVariables␈↓:␈αWe␈αwill␈αuse␈αthe␈αletters␈α␈↓↓u␈↓␈αthru␈α␈↓↓z␈↓␈αwith␈αor␈αwithout␈αsubscripts␈αas␈αvariables.␈α The␈αvariables
␈↓ ↓H␈↓␈↓↓u␈↓␈α
thru␈α
␈↓↓w␈↓␈α∞ will␈α
usually␈α
stand␈α
for␈α∞lists,␈α
while␈α
␈↓↓x␈↓␈α
thru␈α∞␈↓↓z␈↓␈α
will␈α
stand␈α
for␈α∞S-expressions.␈α
 ␈↓↓k␈↓␈α
thru␈α∞␈↓↓n␈↓␈α
are
␈↓ ↓H␈↓integer variables.
␈↓ ↓H␈↓40␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓␈↓αFunction␈α
symbols␈↓:␈α
The␈α
letters␈α
␈↓↓f,␈↓␈α
␈↓↓g␈↓␈α
and␈α
␈↓↓h␈↓␈α
with␈α
or␈α
without␈α
subscripts␈α
are␈α
used␈α
as␈α
function␈α
symbols.
␈↓ ↓H␈↓The␈α⊂LISP␈α⊃function␈α⊂symbols␈α⊃␈↓αa␈↓,␈α⊂␈↓αd␈↓␈α⊃and␈α⊂.␈α⊃(as␈α⊂an␈α⊃infix)␈α⊂are␈α⊃also␈α⊂used␈α⊃as␈α⊂function␈α⊃symbols.␈α⊂ We
␈↓ ↓H␈↓suppose␈α
that␈αeach␈α
function␈αsymbol␈α
takes␈αthe␈α
same␈αdefinite␈α
number␈αof␈α
arguments␈αevery␈α
time␈α
it␈αis
␈↓ ↓H␈↓used.␈α Thus␈αif␈αthe␈αsame␈αletter␈αis␈αused␈αwith␈αdiffering␈αnumbers␈αof␈αarguments,␈αit␈αstands␈αfor␈αdifferent
␈↓ ↓H␈↓function␈αsymbols.␈α Thus␈αwe␈αcan␈αuse␈α␈↓↓<x␈↓β1␈↓↓,␈α...␈α,x␈↓βn␈↓↓>␈↓␈αto␈αrepresent␈αthe␈αlist␈αforming␈αfunctions,␈αbut␈αwe
␈↓ ↓H␈↓shall␈α∂have␈α∂to␈α∂axiomatize␈α∂it␈α⊂separately␈α∂for␈α∂each␈α∂length␈α∂we␈α⊂actually␈α∂use.␈α∂ We␈α∂will␈α∂often␈α⊂use␈α∂one
␈↓ ↓H␈↓argument␈αfunctions␈αsymbols␈αas␈αprefixes,␈αi.e.␈α without␈αbrackets,␈αjust␈αas␈α␈↓αa␈↓␈αand␈α␈↓αd␈↓␈αhave␈αbeen␈αused␈αup
␈↓ ↓H␈↓to now.

␈↓ ↓H␈↓␈↓αPredicate␈α⊃symbols␈↓:␈α⊃The␈α⊃letters␈α⊃␈↓	f␈↓,␈α⊂␈↓	y␈↓␈α⊃and␈α⊃␈↓	x␈↓␈α⊃with␈α⊃or␈α⊂without␈α⊃subscripts␈α⊃are␈α⊃used␈α⊃as␈α⊂predicate
␈↓ ↓H␈↓symbols.␈α∂ We␈α∂will␈α∂also␈α∂use␈α∞the␈α∂LISP␈α∂predicate␈α∂symbol␈α∂␈↓αat␈↓␈α∞as␈α∂a␈α∂constant␈α∂predicate␈α∂symbol.␈α∞ The
␈↓ ↓H␈↓equality␈αsymbol␈α=␈α
is␈αalso␈αused␈α
as␈αan␈αinfix.␈α We␈α
suppose␈αthat␈αeach␈α
predicate␈αsymbol␈αtakes␈αthe␈α
same
␈↓ ↓H␈↓definite␈α∞number␈α∞of␈α∞arguments␈α∞each␈α∂time␈α∞it␈α∞is␈α∞used.␈α∞ Again␈α∂a␈α∞letter␈α∞may␈α∞be␈α∞used␈α∂with␈α∞differing
␈↓ ↓H␈↓numbers␈α∂of␈α∞arguments␈α∂to␈α∞represent␈α∂different␈α∞predicates.␈α∂ Infix␈α∞and␈α∂prefix␈α∞notation␈α∂will␈α∂also␈α∞be
␈↓ ↓H␈↓used where this is customary.

␈↓ ↓H␈↓        Next␈αwe␈αdefine␈αterms,␈αsentences,␈αfunction␈αexpressions␈αand␈αpredicate␈αexpressions␈αinductively.
␈↓ ↓H␈↓A␈αterm␈αis␈αan␈αexpression␈αwhose␈αvalue␈αwill␈αbe␈αan␈αobject␈αlike␈αan␈αS-expression␈αor␈αa␈αnumber␈αwhile␈αa
␈↓ ↓H␈↓sentence␈αhas␈αvalue␈αT␈αor␈αF.␈α Terms␈αare␈αused␈αin␈αmaking␈αsentences,␈αand␈αsentences␈αoccur␈αin␈αterms␈αso
␈↓ ↓H␈↓that␈α∪the␈α∪definitions␈α∪are␈α∪␈↓↓mutually␈↓␈α∪␈↓↓recursive␈↓␈α∪where␈α∪this␈α∪use␈α∪of␈α∪the␈α∪word␈α∪␈↓↓recursive␈↓␈α∪should␈α∪be
␈↓ ↓H␈↓distinguished␈α↔from␈α_its␈α↔use␈α↔in␈α_recursive␈α↔definitions␈α↔of␈α_functions.␈α↔ Function␈α_and␈α↔predicate
␈↓ ↓H␈↓expressions are also involved in the mutual recursion.

␈↓ ↓H␈↓␈↓αTerms␈↓:␈α⊂Constants␈α⊃are␈α⊂terms,␈α⊃and␈α⊂variables␈α⊃are␈α⊂terms.␈α⊃ If␈α⊂␈↓↓f␈↓␈α⊃is␈α⊂a␈α⊃function␈α⊂expression␈α⊃taking␈α⊂␈↓↓n␈↓
␈↓ ↓H␈↓arguments,␈α
and␈α␈↓↓t␈↓β1␈↓↓, ... ,t␈↓βn␈↓↓␈↓␈α
are␈α
terms,␈αthen␈α
␈↓↓f[t␈↓β1␈↓↓, ... ,t␈↓βn␈↓↓]␈↓␈αis␈α
a␈α
term.␈α If␈α
␈↓↓s␈↓␈αis␈α
a␈α
sentence␈αand␈α
␈↓↓t␈↓β1␈↓↓␈↓␈αand␈α
␈↓↓t␈↓β2␈↓↓␈↓
␈↓ ↓H␈↓are␈α∞terms,␈α∞then␈α∞␈↓↓␈↓αif␈↓↓ s ␈↓αthen␈↓↓ t␈↓β1␈↓↓ ␈↓αelse␈↓↓ t␈↓β2␈↓↓␈↓␈α
is␈α∞a␈α∞term.␈α∞ We␈α∞soften␈α
the␈α∞notation␈α∞by␈α∞allowing␈α∞infix␈α
symbols
␈↓ ↓H␈↓where this is customary.

␈↓ ↓H␈↓␈↓αSentences␈↓:␈α⊂If␈α⊂␈↓	f␈↓␈α⊂is␈α⊂a␈α⊂predicate␈α⊃expression␈α⊂taking␈α⊂␈↓↓n␈↓␈α⊂arguments␈α⊂and␈α⊂␈↓↓t␈↓β1␈↓↓, ... ,t␈↓βn␈↓↓␈↓␈α⊂are␈α⊃terms,␈α⊂then
␈↓ ↓H␈↓␈↓↓␈↓	f␈↓↓[t␈↓β1␈↓↓, ... ,t␈↓βn␈↓↓]␈↓␈α∪is␈α∪a␈α∪sentence.␈α∪ Equality␈α∪is␈α∪also␈α∪used␈α∪as␈α∪an␈α∪infixed␈α∪predicate␈α∪symbol␈α∀to␈α∪form
␈↓ ↓H␈↓sentences,␈α
i.e.␈α∞␈↓↓t␈↓β1␈↓↓ = t␈↓β2␈↓↓␈↓␈α
is␈α
a␈α∞sentence.␈α
 If␈α
␈↓↓s␈↓␈α∞is␈α
a␈α
sentence,␈α∞then␈α
¬␈↓↓s␈↓␈α
is␈α∞also␈α
a␈α
sentence.␈α∞ If␈α
␈↓↓r␈↓␈α
and␈α∞␈↓↓s␈↓␈α
are
␈↓ ↓H␈↓sentences,␈αthen␈α
␈↓↓r␈↓␈α∧␈α
␈↓↓s,␈↓␈α␈↓↓r␈↓␈α
∨␈α␈↓↓s,␈↓␈α
␈↓↓r␈↓␈α⊃␈α
␈↓↓s,␈↓␈αand␈α␈↓↓r␈↓␈α
≡␈α␈↓↓s␈↓␈α
are␈αsentences.␈α
 If␈α␈↓↓r,␈↓␈α
␈↓↓s␈↓β1␈↓↓␈↓␈αand␈α
␈↓↓s␈↓β2␈↓↓␈↓␈αare␈α
sentences,␈αthen
␈↓ ↓H␈↓␈↓↓␈↓αif␈↓↓ r ␈↓αthen␈↓↓ s␈↓β1␈↓↓ ␈↓αelse␈↓↓ s␈↓β2␈↓↓␈↓␈α⊗is␈α⊗a␈α⊗sentence.␈α⊗ If␈α⊗␈↓↓x␈↓β1␈↓↓, ..., x␈↓βn␈↓↓␈↓␈α⊗are␈α⊗variables,␈α⊗and␈α⊗␈↓↓s␈↓␈α⊗is␈α⊗a␈α⊗sentence,␈α⊗then
␈↓ ↓H␈↓␈↓↓[∃x␈↓β1␈↓↓ ... x␈↓βn␈↓↓: s]␈↓ and ␈↓↓[∀x␈↓β1␈↓↓ ... x␈↓βn␈↓↓: s]␈↓ are sentences.

␈↓ ↓H␈↓␈↓αFunction␈α
expressions␈↓:␈α∞A␈α
function␈α
symbol␈α∞is␈α
a␈α
function␈α∞expression.␈α
 If␈α
␈↓↓x␈↓β1␈↓↓, ... ,x␈↓βn␈↓↓␈↓␈α∞are␈α
variables
␈↓ ↓H␈↓and ␈↓↓t␈↓ is a term, then ␈↓↓[λx␈↓β1␈↓↓, ... ,x␈↓βn␈↓↓: t]␈↓ is a function expression.

␈↓ ↓H␈↓␈↓αPredicate␈αexpressions␈↓:␈αA␈αpredicate␈αsymbol␈αis␈αa␈αpredicate␈αexpression.␈α If␈α␈↓↓x␈↓β1␈↓↓, ... ,x␈↓βn␈↓↓␈↓␈αare␈αvariables
␈↓ ↓H␈↓and ␈↓↓s␈↓ is a sentence, then ␈↓↓[λx␈↓β1␈↓↓, ... ,x␈↓βn␈↓↓: s]␈↓ is a predicate expression.

␈↓ ↓H␈↓        An␈αoccurrence␈αof␈αa␈αvariable␈α␈↓↓x␈↓␈αis␈αcalled␈αbound␈αif␈αit␈αis␈αin␈αan␈αexpression␈αof␈αone␈αof␈αthe␈αforms
␈↓ ↓H␈↓␈↓↓[λx␈↓β1␈↓↓ ... x␈↓βn␈↓↓: t]␈↓,␈α␈↓↓[λx␈↓β1␈↓↓ ... x␈↓βn␈↓↓: s]␈↓,␈α␈↓↓[∀x␈↓β1␈↓↓ ... x␈↓βn␈↓↓: s]␈↓␈αor␈α␈↓↓[∃x␈↓β1␈↓↓ ... x␈↓βn␈↓↓: s]␈↓␈αwhere␈α␈↓↓x␈↓␈αis␈αone␈αof␈αthe␈αnumbered␈α␈↓↓x␈↓'s.
␈↓ ↓H␈↓If not bound an occurrence is called free.

␈↓ ↓H␈↓        The␈α␈↓↓semantics␈↓␈αof␈αfirst␈αorder␈αlogic␈αconsists␈αof␈αthe␈αrules␈αthat␈αdetermine␈αwhether␈αa␈αsentence␈αis
␈↓ ↓H␈↓true␈αor␈αfalse.␈α However,␈αthe␈αtruth␈αor␈αfalsity␈αof␈αa␈αsentence␈αis␈αrelative␈αto␈αthe␈αinterpretation␈αassigned
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *41


␈↓ ↓H␈↓to␈α
the␈α
constants,␈α
the␈α∞function␈α
and␈α
predicate␈α
symbols␈α
and␈α∞the␈α
free␈α
variables␈α
of␈α
the␈α∞formula.␈α
 We
␈↓ ↓H␈↓proceed as follows:

␈↓ ↓H␈↓        We␈αbegin␈αby␈αchoosing␈αa␈αdomain.␈α In␈αmost␈αcases,␈αthe␈αdomain␈αwill␈αinclude␈αthe␈αS-expressions,
␈↓ ↓H␈↓and␈αany␈αS-expression␈α
constants␈αappearing␈αin␈αthe␈α
formula␈αstand␈αfor␈α
themselves.␈α We␈αwill␈αallow␈α
for
␈↓ ↓H␈↓the␈α
possibility␈α
that␈αother␈α
objects␈α
than␈αS-expressions␈α
exist,␈α
and␈αsome␈α
constants␈α
may␈αdesignate␈α
them.
␈↓ ↓H␈↓A␈αspecial␈α
constant␈αsymbol␈α␈↓πT␈↓␈α
is␈αused␈αfor␈α
the␈αvalue␈αof␈α
the␈αfunction␈αdefined␈α
by␈αa␈αLisp␈α
program␈αin
␈↓ ↓H␈↓case the computation doesn't terminate; its use requires a justification that will be given later.

␈↓ ↓H␈↓        Each␈αfunction␈αor␈α
predicate␈αsymbol␈αis␈α
assigned␈αa␈αfunction␈αor␈α
predicate␈αon␈αthe␈α
domain.␈α We
␈↓ ↓H␈↓will␈α∞normally␈α∂assign␈α∞to␈α∂the␈α∞basic␈α∂LISP␈α∞function␈α∂and␈α∞predicate␈α∂symbols␈α∞the␈α∂corresponding␈α∞basic
␈↓ ↓H␈↓LISP␈α∞functions␈α∞and␈α∞predicates.␈α∞ Each␈α∞variable␈α∞appearing␈α∞free␈α∞in␈α∞a␈α∞sentence␈α∞is␈α∞also␈α∞assigned␈α∞an
␈↓ ↓H␈↓element␈α⊂of␈α∂the␈α⊂domain.␈α∂ All␈α⊂these␈α⊂assignments␈α∂constitute␈α⊂an␈α∂interpretation,␈α⊂and␈α∂the␈α⊂truth␈α⊂of␈α∂a
␈↓ ↓H␈↓sentence is relative to the interpretation.

␈↓ ↓H␈↓        The␈α⊂truth␈α∂of␈α⊂a␈α∂sentence␈α⊂is␈α⊂determined␈α∂from␈α⊂the␈α∂values␈α⊂of␈α∂its␈α⊂constituents␈α⊂by␈α∂evaluating
␈↓ ↓H␈↓successively␈α∞larger␈α∞subexpressions.␈α
 The␈α∞rules␈α∞for␈α
handling␈α∞functions␈α∞and␈α∞predicates,␈α
conditional
␈↓ ↓H␈↓expressions,␈αequality,␈αand␈αBoolean␈αexpressions␈αare␈αexactly␈αthe␈αsame␈αas␈αthose␈αwe␈αhave␈αused␈αin␈αthe
␈↓ ↓H␈↓previous chapters.  We need only explain quantifiers:

␈↓ ↓H␈↓        ␈↓↓[∀x␈↓β1␈↓↓ ... x␈↓βn␈↓↓: s]␈↓␈α⊃is␈α∩assigned␈α⊃true␈α∩if␈α⊃and␈α⊃only␈α∩if␈α⊃␈↓↓s␈↓␈α∩is␈α⊃assigned␈α⊃true␈α∩for␈α⊃␈↓↓all␈↓␈α∩assignments␈α⊃of
␈↓ ↓H␈↓elements␈α∞of␈α∞the␈α
domain␈α∞to␈α∞the␈α
␈↓↓x␈↓'s.␈α∞ If␈α∞␈↓↓s␈↓␈α
has␈α∞free␈α∞variables␈α
that␈α∞are␈α∞not␈α
among␈α∞the␈α∞␈↓↓x␈↓'s,␈α∞then␈α
the
␈↓ ↓H␈↓truth␈α⊗of␈α⊗the␈α⊗sentence␈α⊗depends␈α⊗on␈α⊗the␈α⊗values␈α⊗assigned␈α⊗to␈α⊗these␈α⊗remaining␈α↔free␈α⊗variables.
␈↓ ↓H␈↓␈↓↓[∃x␈↓β1␈↓↓ ... x␈↓βn␈↓↓: s]␈↓␈α
is␈α
assigned␈α
true␈α
if␈αand␈α
only␈α
if␈α
␈↓↓s␈↓␈α
is␈α
assigned␈αtrue␈α
for␈α
␈↓↓some␈↓␈α
assignment␈α
of␈α
values␈αin
␈↓ ↓H␈↓the domain to the ␈↓↓x␈↓'s.  Free variables are handled just as before.

␈↓ ↓H␈↓        ␈↓↓[λx␈↓β1␈↓↓ ... x␈↓βn␈↓↓: e]␈↓␈α∂is␈α⊂assigned␈α∂a␈α∂function␈α⊂or␈α∂predicate␈α∂according␈α⊂to␈α∂whether␈α∂␈↓↓e␈↓␈α⊂is␈α∂a␈α∂term␈α⊂or␈α∂a
␈↓ ↓H␈↓sentence.␈α The␈αvalue␈αof␈α␈↓↓[λx␈↓β1␈↓↓ ... x␈↓βn␈↓↓: e][t␈↓β1␈↓↓,...,t␈↓βn␈↓↓]␈↓␈αis␈αobtained␈αby␈αevaluating␈αthe␈α␈↓↓t␈↓'s␈αand␈αusing␈αthese
␈↓ ↓H␈↓values␈α
as␈α
values␈α
of␈α
the␈α
␈↓↓x␈↓'s␈α
in␈α
the␈α
evaluation␈α
of␈α␈↓↓e.␈↓␈α
 If␈α
␈↓↓e␈↓␈α
has␈α
free␈α
variables␈α
in␈α
addition␈α
to␈α
the␈α␈↓↓x␈↓'s,␈α
the
␈↓ ↓H␈↓function assigned will depend on them too.

␈↓ ↓H␈↓        Those␈α
who␈αare␈α
familiar␈αwith␈α
the␈α
lambda␈αcalculus␈α
should␈αnote␈α
that␈α
λ␈αis␈α
being␈αused␈α
here␈αin␈α
a
␈↓ ↓H␈↓very␈α
limited␈α
way.␈α Namely,␈α
the␈α
variables␈αin␈α
a␈α
lambda-expression␈α
take␈αonly␈α
elements␈α
of␈αthe␈α
domain
␈↓ ↓H␈↓as␈α⊂values,␈α⊂whereas␈α∂the␈α⊂essence␈α⊂of␈α∂the␈α⊂lambda␈α⊂calculus␈α∂is␈α⊂that␈α⊂they␈α∂take␈α⊂arbitrary␈α⊂functions␈α∂as
␈↓ ↓H␈↓values.  We may call these restricted lambda expressions ␈↓↓first␈↓ ␈↓↓order␈↓ ␈↓↓lambdas.␈↓



␈↓ ↓H␈↓3.  ␈↓αConditional Forms.␈↓


␈↓ ↓H␈↓        All the properties we shall use of conditional forms follow from the relation

␈↓ ↓H␈↓␈↓ β>␈↓↓[s ⊃ [␈↓αif␈↓↓ s ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b] = a] ∧ [¬s ⊃ [␈↓αif␈↓↓ s ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b] = b] ␈↓. 

␈↓ ↓H␈↓        It␈α
is␈α∞worthwhile␈α
to␈α
list␈α∞separately␈α
some␈α
properties␈α∞of␈α
conditional␈α
terms.␈α∞ First␈α
we␈α∞have␈α
the
␈↓ ↓H␈↓obvious
␈↓ ↓H␈↓42␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓␈↓ ¬␈↓↓␈↓αif␈↓↓ T ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b = a            ␈↓ 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ ¬␈↓↓␈↓αif␈↓↓ F ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b = b .          ␈↓ 

␈↓ ↓H␈↓Next we have a ␈↓↓distributive␈↓ ␈↓↓law␈↓ for functions applied to conditional terms, namely

␈↓ ↓H␈↓␈↓ ∧#␈↓↓f[␈↓αif␈↓↓ s ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b] = ␈↓αif␈↓↓ s ␈↓αthen␈↓↓ f[a] ␈↓αelse␈↓↓ f[b] ␈↓. 

␈↓ ↓H␈↓This␈α
applies␈αto␈α
predicates␈αas␈α
well␈αas␈α
functions␈αand␈α
can␈α
also␈αbe␈α
used␈αwhen␈α
one␈αof␈α
the␈αarguments␈α
of
␈↓ ↓H␈↓a␈αfunction␈αof␈αseveral␈αarguments␈αis␈αa␈αconditional␈αterm.␈α It␈αalso␈αapplies␈αwhen␈αone␈αof␈αthe␈αterms␈αof␈αa
␈↓ ↓H␈↓conditional term is itself a conditional term.

␈↓ ↓H␈↓Thus

␈↓ ↓H␈↓␈↓ β∩␈↓↓␈↓αif␈↓↓ [␈↓αif␈↓↓ r ␈↓αthen␈↓↓ s␈↓β1␈↓↓ ␈↓αelse␈↓↓ s␈↓β2␈↓↓] ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b =                                      ␈↓
␈↓ ↓H␈↓␈↓ βl␈↓↓␈↓αif␈↓↓ r ␈↓αthen␈↓↓ [␈↓αif␈↓↓ s␈↓β1␈↓↓ ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b] ␈↓αelse␈↓↓ [␈↓αif␈↓↓ s␈↓β2␈↓↓ ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b]␈↓

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ αn␈↓↓␈↓αif␈↓↓ r ␈↓αthen␈↓↓ [␈↓αif␈↓↓ s ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b] ␈↓αelse␈↓↓ c =                                                ␈↓
␈↓ ↓H␈↓␈↓ β>␈↓↓␈↓αif␈↓↓ s ␈↓αthen␈↓↓ [␈↓αif␈↓↓ r ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ c] ␈↓αelse␈↓↓ [␈↓αif␈↓↓ r ␈↓αthen␈↓↓ b ␈↓αelse␈↓↓ c] .          ␈↓

␈↓ ↓H␈↓        When␈αthe␈αexpressions␈αfollowing␈α␈↓αthen␈↓␈αand␈α␈↓αelse␈↓␈αare␈αsentences,␈αthen␈αthe␈αconditional␈α
term␈αcan
␈↓ ↓H␈↓be replaced by a sentence according to

␈↓ ↓H␈↓␈↓ ∧1␈↓↓[␈↓αif␈↓↓ r ␈↓αthen␈↓↓ s␈↓β1␈↓↓ ␈↓αelse␈↓↓ s␈↓β2␈↓↓] ≡ [r ∧ s␈↓β1␈↓↓] ∨ [¬r ∧ s␈↓β2␈↓↓] ␈↓. 

␈↓ ↓H␈↓These␈α
two␈α
rules␈α
permit␈αeliminating␈α
conditional␈α
terms␈α
from␈αsentences␈α
by␈α
first␈α
using␈αdistributivity␈α
to
␈↓ ↓H␈↓move␈α
the␈α
conditionals␈α
to␈α
the␈α
outside␈α
of␈α
any␈α
functions␈α
and␈α
then␈α
replacing␈α
the␈α
conditional␈α
term␈αby␈α
a
␈↓ ↓H␈↓Boolean expression.

␈↓ ↓H␈↓        Note␈αthat␈αthe␈αelimination␈αof␈α
conditional␈αterms␈αmay␈αincrease␈αthe␈α
size␈αof␈αa␈αsentence,␈αbecause␈α
␈↓↓r␈↓
␈↓ ↓H␈↓occurs␈αtwice␈αin␈αthe␈α
right␈αhand␈αside␈αof␈α
the␈αabove␈αequivalence.␈α In␈α
the␈αmost␈αunfavorable␈αcase,␈α
␈↓↓r␈↓␈αis
␈↓ ↓H␈↓dominates␈α∩the␈α⊃size␈α∩of␈α⊃the␈α∩expression␈α⊃so␈α∩that␈α⊃writing␈α∩it␈α⊃twice␈α∩almost␈α⊃doubles␈α∩the␈α⊃size␈α∩of␈α⊃the
␈↓ ↓H␈↓expression.

␈↓ ↓H␈↓        Suppose␈αthat␈α␈↓↓a␈↓␈αand␈α␈↓↓b␈↓␈αin␈α␈↓↓␈↓αif␈↓↓ s ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b␈↓␈αare␈αexpressions␈αthat␈αmay␈αcontain␈αthe␈αsentence␈α␈↓↓s.␈↓
␈↓ ↓H␈↓Occurrences␈αof␈α␈↓↓s␈↓␈α
in␈α␈↓↓a␈↓␈αcan␈αbe␈α
replaced␈αby␈αT,␈α
and␈αoccurrences␈αof␈α␈↓↓s␈↓␈α
in␈α␈↓↓b␈↓␈αcan␈α
be␈αreplaced␈αby␈αF.␈α
 This
␈↓ ↓H␈↓follows from the fact that ␈↓↓a␈↓ is only evaluated if ␈↓↓s␈↓ is true and ␈↓↓b␈↓ is evaluated only if ␈↓↓s␈↓ is false.

␈↓ ↓H␈↓        This␈α∂leads␈α⊂to␈α∂a␈α⊂strengthened␈α∂form␈α⊂of␈α∂the␈α⊂law␈α∂of␈α⊂replacement␈α∂of␈α⊂equals␈α∂by␈α⊂equals.␈α∂ The
␈↓ ↓H␈↓ordinary␈αform␈αof␈αthe␈αlaw␈αsays␈αthat␈αif␈αwe␈αhave␈α␈↓↓e = e'␈↓,␈αthen␈αwe␈αcan␈αreplace␈αany␈αoccurrence␈αof␈α
␈↓↓e␈↓␈αin
␈↓ ↓H␈↓an␈α
expression␈α∞by␈α
an␈α
occurrence␈α∞of␈α
␈↓↓e'.␈↓␈α
 However,␈α∞if␈α
we␈α
want␈α∞to␈α
replace␈α
␈↓↓e␈↓␈α∞by␈α
␈↓↓e'␈↓␈α
within␈α∞␈↓↓a␈↓␈α
within
␈↓ ↓H␈↓␈↓↓␈↓αif␈↓↓ s ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ b␈↓,␈α∞then␈α∞we␈α∞need␈α∞only␈α∞prove␈α∞␈↓↓s ⊃ e =e'␈↓,␈α∞and␈α∞to␈α∞make␈α∞the␈α∞replacement␈α∞within␈α∞␈↓↓b␈↓␈α
we
␈↓ ↓H␈↓need only prove ␈↓↓¬s ⊃ e = e'␈↓.
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *43


␈↓ ↓H␈↓        More␈αfacts␈αabout␈αconditional␈αterms␈αare␈αgiven␈αin␈α(McCarthy␈α1963)␈αincluding␈αa␈αdiscussion␈αof
␈↓ ↓H␈↓canonical␈αforms␈αthat␈αparallels␈α
the␈αcanonical␈αforms␈αof␈α
Boolean␈αterms.␈α Any␈αquestion␈αof␈α
equivalence
␈↓ ↓H␈↓of␈α
conditional␈α∞terms␈α
is␈α
decidable␈α∞by␈α
truth␈α∞tables␈α
analogously␈α
to␈α∞the␈α
decidability␈α∞of␈α
propositional
␈↓ ↓H␈↓sentences.



␈↓ ↓H␈↓4.  ␈↓αLambda-expressions.␈↓


␈↓ ↓H␈↓        The␈α∪only␈α∩rule␈α∪required␈α∩for␈α∪handling␈α∪lambda-expressions␈α∩in␈α∪first␈α∩order␈α∪logic␈α∪is␈α∩called
␈↓ ↓H␈↓␈↓↓lambda-conversion.␈↓  Essentially it is

␈↓ ↓H␈↓␈↓ βt␈↓↓[λx: e][a] =␈↓ < the result of substituting ␈↓↓a␈↓ for ␈↓↓x␈↓ in ␈↓↓e␈↓ >. 

␈↓ ↓H␈↓As examples of this rule, we have

␈↓ ↓H␈↓␈↓ ∧/␈↓↓[λx: ␈↓αa␈↓↓␈α∧x . y][u . v] = [␈↓αa␈↓↓␈α∧[u . v]] . y .           ␈↓ 

␈↓ ↓H␈↓However,␈αa␈α
complication␈αrequires␈α
modifying␈αthe␈α
rule.␈α Namely,␈α
we␈αcan't␈α
substitute␈αfor␈α
a␈αvariable␈α
␈↓↓x␈↓
␈↓ ↓H␈↓an␈αexpression␈α␈↓↓e␈↓␈αthat␈αhas␈αa␈αfree␈αvariable␈α␈↓↓y␈↓␈αinto␈αa␈αcontext␈αin␈αwhich␈α␈↓↓y␈↓␈αis␈αbound.␈α Thus␈αit␈αwould␈αbe
␈↓ ↓H␈↓wrong␈αto␈αsubstitute␈α␈↓↓y + z␈↓␈αfor␈α␈↓↓x␈↓␈αin␈α␈↓↓∀y: [x + y = z]␈↓␈αor␈αinto␈αthe␈αterm␈α␈↓↓[λy: x + y][u + v]␈↓.␈α Before␈αdoing
␈↓ ↓H␈↓the␈αsubstitution,␈αthe␈αvariable␈α␈↓↓y␈↓␈αwould␈αhave␈αto␈αbe␈αreplaced␈αin␈αall␈αits␈αbound␈αoccurrences␈αby␈αa␈αfresh
␈↓ ↓H␈↓variable.

␈↓ ↓H␈↓        Lambda-expressions␈α∀can␈α∀always␈α∃be␈α∀eliminated␈α∀from␈α∃sentences␈α∀and␈α∀terms␈α∃by␈α∀lambda-
␈↓ ↓H␈↓conversion,␈αbut␈αthe␈αexpression␈αmay␈α
increase␈αgreatly␈αin␈αlength␈αif␈α
a␈αlengthy␈αterm␈αreplaces␈αa␈α
variable
␈↓ ↓H␈↓that␈α∞occurs␈α∞more␈α∞than␈α∞once␈α∞in␈α
␈↓↓e.␈↓␈α∞ It␈α∞is␈α∞easy␈α∞to␈α∞make␈α
an␈α∞expression␈α∞of␈α∞length␈α∞proportional␈α∞to␈α
␈↓↓n␈↓
␈↓ ↓H␈↓whose␈α⊃length␈α⊃is␈α⊃proportional␈α∩to␈α⊃2␈↓∧n␈↓␈α⊃after␈α⊃conversion␈α∩of␈α⊃its␈α⊃␈↓↓n␈↓␈α⊃nested␈α∩lambda-expressions.␈α⊃ For
␈↓ ↓H␈↓example

␈↓ ↓H␈↓        ␈↓ ∧T␈↓↓λx␈↓β1␈↓↓: [x␈↓β1␈↓↓.x␈↓β1␈↓↓][ ... [λx␈↓βn␈↓↓: [x␈↓βn␈↓↓.x␈↓βn␈↓↓][␈↓¬A␈↓↓]] ... ]␈↓ 

␈↓ ↓H␈↓becomes

␈↓ ↓H␈↓        ␈↓¬(A . A)␈↓,

␈↓ ↓H␈↓        ␈↓¬((A . A) . (A . A))␈↓,

␈↓ ↓H␈↓or

␈↓ ↓H␈↓        ␈↓¬((((A . A) . (A . A)) . ((A . A) . (A . A))) . ((A . A) . (A . A)) . ((A . A) . (A . A))))␈↓

␈↓ ↓H␈↓for ␈↓↓n␈↓ = 1, 2, or 4 respectively.
␈↓ ↓H␈↓44␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓5.  ␈↓αFirst Order Axioms for LISP.␈↓


␈↓ ↓H␈↓         We␈α∪are␈α∪interested␈α∩in␈α∪the␈α∪first␈α∪order␈α∩theory␈α∪of␈α∪LISP.␈α∪ That␈α∩is,␈α∪we␈α∪are␈α∪interested␈α∩ in
␈↓ ↓H␈↓determining␈αwhat␈αsentences␈α
involving␈αvariables␈αranging␈αover␈α
lists␈αand␈αS-expressions␈αand␈α
function
␈↓ ↓H␈↓and␈αpredicate␈α
symbols␈αrepresenting␈αLISP␈α
functions␈αand␈α
predicates␈αare␈αtrue.␈α
 In␈αorder␈α
to␈αdescribe
␈↓ ↓H␈↓this␈α∞theory␈α∞we␈α∞represent␈α∞the␈α∞algebraic␈α∂facts␈α∞about␈α∞lists,␈α∞S-expressions␈α∞and␈α∞basic␈α∂LISP␈α∞functions
␈↓ ↓H␈↓and predicates by axioms (first order sentences of the theory which we assume to be true).

␈↓ ↓H␈↓        First␈α
are␈α
the␈α
axioms␈α
describing␈α
the␈α
domain␈α
SE␈α
of␈α
S-expresions,␈α
its␈α
extension␈α
SE␈↓∧+␈↓ = SE ∪ {␈↓πT␈↓}
␈↓ ↓H␈↓and␈α∪the␈α∪subdomain␈α∪of␈α∩lists.␈α∪ Lists␈α∪are␈α∪those␈α∩S-expressions␈α∪having␈α∪the␈α∪property␈α∪that␈α∩taking
␈↓ ↓H␈↓successive␈α␈↓↓cdr␈↓'s␈αwill␈αeventually␈αreach␈α␈↓¬NIL␈↓.␈α (The␈α␈↓↓car␈↓␈αof␈αa␈αlist␈αis␈αnot␈αrequired␈αto␈αbe␈αa␈αlist,␈α it␈αcan␈αbe
␈↓ ↓H␈↓any␈α∞S-expression.)␈α
 We␈α∞use␈α
lower␈α∞case␈α∞variables␈α
␈↓↓x,␈↓␈α∞␈↓↓y,␈↓␈α
and␈α∞␈↓↓z␈↓␈α∞to␈α
range␈α∞over␈α
SE␈α∞and␈α∞upper␈α
case
␈↓ ↓H␈↓variables␈α
␈↓↓X,␈↓␈α
␈↓↓Y␈↓␈α
and␈α
␈↓↓Z␈↓␈α
to␈αrange␈α
over␈α
SE␈↓∧+␈↓.␈α
 The␈α
lower␈α
case␈αvaribles␈α
␈↓↓u,␈↓␈α
␈↓↓v␈↓␈α
and␈α
␈↓↓w␈↓␈α
range␈α
over␈αlists.
␈↓ ↓H␈↓This is expressed by the axioms L0 to L2.

␈↓ ↓H␈↓␈↓¬L0: ␈↓   ␈↓↓∀X Y Z: [X = ␈↓πT␈↓↓ ∨ issexp X] ∧ [Y = ␈↓πT␈↓↓ ∨ issexp Y] ∧ [Z = ␈↓πT␈↓↓ ∨ issexp Z]␈↓

␈↓ ↓H␈↓␈↓¬L1: ␈↓   ␈↓↓∀x y z: [issexp x ∧ issexp y ∧ issexp z]␈↓

␈↓ ↓H␈↓␈↓¬L2: ␈↓    ␈↓↓∀u v w: [islist u ∧ islist v ∧ islist w]␈↓

␈↓ ↓H␈↓        The␈αpoint␈αof␈α
these␈α"housekeeping"␈αaxioms␈α
is␈αto␈αallow␈αan␈α
abreviated␈αform␈αfor␈α
sentences.␈αIn
␈↓ ↓H␈↓particular␈α~whenever␈α~a␈α≠sentence␈α~of␈α~the␈α≠form␈α~␈↓↓∀x: s␈↓␈α~occurs␈α≠this␈α~is␈α~an␈α≠abbreviation␈α~for
␈↓ ↓H␈↓␈↓↓∀x: issexp x ⊃ s␈↓.␈α∞Similarly␈α∂for␈α∞␈↓↓y␈↓␈α∂and␈α∞␈↓↓z.␈↓␈α∂Whenever␈α∞a␈α∞ sentence␈α∂of␈α∞the␈α∂form␈α∞␈↓↓∀u: s␈↓␈α∂occurs␈α∞it␈α∂is␈α∞an
␈↓ ↓H␈↓abbreviation␈α
for␈α
␈↓↓∀u: islist u ⊃ s␈↓.␈α
Similarly␈α
for␈α
␈↓↓v␈↓␈α∞and␈α
␈↓↓w.␈↓␈α
 Thus␈α
whenever␈α
a␈α
sentence␈α
of␈α∞the␈α
form
␈↓ ↓H␈↓␈↓↓∀x:␈αs␈↓␈αis␈αused␈αby␈αsubstituting␈αsome␈αexpression␈αfor␈α␈↓↓x␈↓␈αin␈α␈↓↓s␈↓␈αit␈αmust␈αbe␈αthe␈αcase␈αthat␈αthe␈αexpression␈αis
␈↓ ↓H␈↓an S-expression. Similarly for ␈↓↓u␈↓ in ␈↓↓∀u: s␈↓ and Lists.

␈↓ ↓H␈↓        The remaining "algebraic" axioms for lists and S-expressions are as follows:

␈↓ ↓H␈↓␈↓¬L3: ␈↓   ␈↓↓∀u: issexp u␈↓

␈↓ ↓H␈↓␈↓¬L4: ␈↓    ␈↓↓¬issexp ␈↓πT␈↓↓␈↓

␈↓ ↓H␈↓␈↓¬L5: ␈↓   ␈↓↓islist ␈↓¬NIL␈↓↓␈↓

␈↓ ↓H␈↓␈↓¬L6: ␈↓   ␈↓↓∀u: [␈↓αn␈↓↓␈α∧u ≡ ␈↓αat␈↓↓␈αεu]␈↓

␈↓ ↓H␈↓␈↓¬L7: ␈↓   ␈↓↓∀u: [␈↓αat␈↓↓␈αεu ≡ u=␈↓¬NIL␈↓↓]␈↓

␈↓ ↓H␈↓        Next are the "algebraic" axioms describing the basic LISP functions.

␈↓ ↓H␈↓␈↓¬L8: ␈↓   ␈↓↓∀x y: issexp [x . y]␈↓

␈↓ ↓H␈↓␈↓¬L9: ␈↓   ␈↓↓∀x u: islist [x . u]␈↓

␈↓ ↓H␈↓␈↓¬L10: ␈↓  ␈↓↓∀x: [¬␈↓αat␈↓↓␈αεx ⊃ issexp ␈↓αa␈↓↓␈α∧x]␈↓
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *45


␈↓ ↓H␈↓␈↓¬L11: ␈↓  ␈↓↓∀x: [¬␈↓αat␈↓↓␈αεx ⊃ issexp ␈↓αd␈↓↓␈α∧x]␈↓

␈↓ ↓H␈↓␈↓¬L12: ␈↓  ␈↓↓∀u: [¬␈↓αn␈↓↓␈α∧u ⊃ islist ␈↓αd␈↓↓␈α∧u]␈↓

␈↓ ↓H␈↓␈↓¬L13: ␈↓  ␈↓↓∀x y: ␈↓αa␈↓↓␈α∧[x . y] = x␈↓

␈↓ ↓H␈↓␈↓¬L14: ␈↓  ␈↓↓∀x y: ␈↓αd␈↓↓␈α∧[x . y] = y␈↓

␈↓ ↓H␈↓␈↓¬L15: ␈↓  ␈↓↓∀x y: ¬␈↓αat␈↓↓␈αε[x . y]␈↓

␈↓ ↓H␈↓␈↓¬L16: ␈↓  ␈↓↓∀x: [¬␈↓αat␈↓↓␈αεx ⊃ [␈↓αa␈↓↓␈α∧x . ␈↓αd␈↓↓␈α∧x] = x]␈↓

␈↓ ↓H␈↓        An alternate form of L16 which we will find useful is

␈↓ ↓H␈↓␈↓¬EQ-SEXP: ␈↓      ␈↓↓∀x y: [[¬␈↓αat␈↓↓␈αεx ∧ ¬␈↓αat␈↓↓␈αεy] ⊃ [␈↓αa␈↓↓␈α∧x = ␈↓αa␈↓↓␈α∧y ∧ ␈↓αd␈↓↓␈α∧x = ␈↓αd␈↓↓␈α∧y ≡ x = y]] ␈↓.

␈↓ ↓H␈↓        These␈α
axioms␈α
are␈α
analogous␈α
to␈α
the␈αalgebraic␈α
part␈α
of␈α
Peano's␈α
axioms␈α
for␈α
the␈αnon-negative
␈↓ ↓H␈↓integers.␈α The␈αanalogy␈αcan␈αbe␈αmade␈αclear␈αif␈αwe␈αwrite␈αPeano's␈αaxioms␈αusing␈α␈↓↓n'␈↓␈αfor␈αthe␈αsuccessor␈α
of
␈↓ ↓H␈↓␈↓↓n␈↓ and ␈↓↓n␈↓␈↓∧-␈↓ for the predecessor of ␈↓↓n.␈↓  Peano's algebraic axioms then become

␈↓ ↓H␈↓␈↓ ∧x␈↓↓∀n: n' ≠ 0 ,                         ␈↓ 

␈↓ ↓H␈↓␈↓ ∧|␈↓↓∀n: (n')␈↓∧-␈↓↓ = n ,                      ␈↓ 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ ∧x␈↓↓∀n: n ≠ 0 ⊃ (n␈↓∧-␈↓↓)' = n .            ␈↓ 

␈↓ ↓H␈↓Lists␈αcan␈αmodel␈αintegers␈αif␈αwe␈αidentify␈α0␈αwith␈α␈↓¬NIL␈↓␈αand␈αassume␈αthat␈αthere␈αis␈αonly␈αone␈αobject␈α(say␈α1)
␈↓ ↓H␈↓that can serve as a list element.  Then ␈↓↓n' = cons[1,n]␈↓, and ␈↓↓n␈↓∧-␈↓↓ = ␈↓αd␈↓↓␈α∧n␈↓.



␈↓ ↓H␈↓6.  ␈↓αAxiom Schemas of Induction.␈↓


␈↓ ↓H␈↓        Clearly␈α∞S-expressions␈α
and␈α∞lists␈α
satisfy␈α∞the␈α∞axioms␈α
given␈α∞for␈α
them,␈α∞but␈α∞unfortunately␈α
these
␈↓ ↓H␈↓algebraic␈α∞axioms␈α∞are␈α∞insufficient␈α∞to␈α∞characterize␈α∂them.␈α∞ For␈α∞example,␈α∞consider␈α∞a␈α∞domain␈α∂of␈α∞one
␈↓ ↓H␈↓element ␈↓↓a␈↓ satisfying

␈↓ ↓H␈↓␈↓ ¬¬␈↓↓␈↓αa␈↓↓␈α∧a = ␈↓αd␈↓↓␈α∧a = a . a = a .            ␈↓ 

␈↓ ↓H␈↓It␈αsatisfies␈αthe␈αalgebraic␈αaxioms␈αfor␈αS-expressions.␈α We␈αcan␈αexclude␈αit␈αby␈αan␈αaxiom␈α␈↓↓∀x:␈α[␈↓αa␈↓↓␈α∧x␈α
≠␈αx]␈↓,
␈↓ ↓H␈↓but␈αthis␈αwon't␈α
exclude␈αother␈αcircular␈αlist␈α
structures␈αthat␈αeventually␈αreturn␈α
to␈αthe␈αsame␈α
element␈αby
␈↓ ↓H␈↓some␈α∞␈↓αa␈↓-␈↓αd␈↓␈α∂chain.␈α∞ Actually␈α∂we␈α∞want␈α∂to␈α∞exclude␈α∞all␈α∂infinite␈α∞chains,␈α∂because␈α∞most␈α∂LISP␈α∞programs
␈↓ ↓H␈↓won't␈αterminate␈αunless␈α
every␈α␈↓αa␈↓-␈↓αd␈↓␈αchain␈α
eventually␈αterminates␈αin␈α
an␈αatom.␈α This␈α
cannot␈αbe␈αdone␈α
by
␈↓ ↓H␈↓any finite set of axioms.
␈↓ ↓H␈↓46␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓                In␈α∂order␈α∂to␈α∂exclude␈α⊂circular␈α∂and␈α∂infinite␈α∂list␈α⊂structures␈α∂we␈α∂need␈α∂axiom␈α⊂schemas␈α∂of
␈↓ ↓H␈↓induction analogous to Peano's for the integers.  Peano's induction schema is ordinarily written

␈↓ ↓H␈↓␈↓ ∧S␈↓↓P(0) ∧ ∀n: (P(n) ⊃ P(n')) ⊃ ∀n: P(n) .␈↓ 

␈↓ ↓H␈↓Here␈α␈↓↓P(n)␈↓␈αis␈αan␈αarbitrary␈α
predicate␈αof␈αintegers,␈αand␈αwe␈α
get␈αparticular␈αinstances␈αof␈αthe␈α
schema␈αby
␈↓ ↓H␈↓substituting␈αparticular␈αpredicates.␈α It␈αis␈αcalled␈αan␈αaxiom␈αschema␈αrather␈αthan␈αan␈αaxiom,␈αbecause␈αwe
␈↓ ↓H␈↓consider␈α∂the␈α∂schema,␈α∂which␈α∂is␈α∂not␈α∂properly␈α⊂a␈α∂sentence␈α∂of␈α∂first␈α∂order␈α∂logic,␈α∂as␈α∂standing␈α⊂for␈α∂the
␈↓ ↓H␈↓infinite␈α⊂collection␈α⊂of␈α∂axioms␈α⊂that␈α⊂arise␈α⊂from␈α∂it␈α⊂by␈α⊂substituting␈α⊂all␈α∂possible␈α⊂predicates␈α⊂for␈α⊂␈↓↓P.␈α∂ ␈↓
␈↓ ↓H␈↓The S-expression induction schema is

␈↓ ↓H␈↓␈↓¬SEXPINDUCTION: ␈↓   ␈↓↓∀x: [␈↓αat␈↓↓␈αεx ⊃ ␈↓	F␈↓↓ x] ∧ ∀x: [¬␈↓αat␈↓↓␈αεx ∧ ␈↓	F␈↓↓ ␈↓αa␈↓↓␈α∧x ∧ ␈↓	F␈↓↓ ␈↓αd␈↓↓␈α∧x ⊃ ␈↓	F␈↓↓ x] ⊃ ∀x: ␈↓	F␈↓↓ x ␈↓.

␈↓ ↓H␈↓        The corresponding axiom schema for lists is

␈↓ ↓H␈↓␈↓¬LISTINDUCTION: ␈↓   ␈↓↓∀u: [␈↓αn␈↓↓␈α∧u ⊃ ␈↓	F␈↓↓ u] ∧ ∀u: [¬␈↓αn␈↓↓␈α∧u ∧ ␈↓	F␈↓↓ ␈↓αd␈↓↓␈α∧u ⊃ ␈↓	F␈↓↓ u] ⊃ ∀u: ␈↓	F␈↓↓ u ␈↓.

␈↓ ↓H␈↓Here ␈↓	F␈↓ is a predicate variable.

␈↓ ↓H␈↓        These␈α∞schemas␈α∞are␈α
called␈α∞principles␈α∞of␈α
␈↓↓structural␈↓␈α∞␈↓↓induction,␈↓␈α∞since␈α
the␈α∞induction␈α∞is␈α∞on␈α
the
␈↓ ↓H␈↓structure␈α
of␈α
the␈α
entities␈α
involved.␈α
Other␈α
schemas␈α
derived␈α
from␈α
principles␈α
of␈α∞␈↓↓structural␈↓␈α
␈↓↓induction␈↓
␈↓ ↓H␈↓are␈αpossible␈αand␈αthe␈αbest␈αschema␈αto␈αuse␈αdepends␈αstongly␈αon␈αthe␈αproblem␈αat␈αhand.␈α Some␈αexamples
␈↓ ↓H␈↓will be given in a later section.

␈↓ ↓H␈↓        Even␈αthe␈αaxiom␈αschemas␈αdon't␈αassure␈αus␈αthat␈αthe␈αonly␈αdomain␈αsatisfying␈αthe␈αaxioms␈αis␈αthat
␈↓ ↓H␈↓of␈αthe␈αintegers␈αor␈αthe␈αS-expressions␈αas␈αthe␈α
case␈αmay␈αbe.␈α Any␈αfirst␈αorder␈αtheory␈αwhose␈αaxioms␈α
can
␈↓ ↓H␈↓be␈αgiven␈αeffectively␈α
admits␈αthe␈αso-called␈α␈↓↓non-standard models.␈↓␈α
 However,␈αit␈αseems␈αlikely␈α
that␈αthe
␈↓ ↓H␈↓non-standard␈α
models␈α
of␈α
S-expressions,␈α
like␈α
the␈α
non-standard␈α
models␈α
of␈α
integers,␈α
will␈α
agree␈αwith
␈↓ ↓H␈↓the standard model for sentences of practical interest.



␈↓ ↓H␈↓7.  ␈↓αA Simple Example. ␈↓


␈↓ ↓H␈↓        In␈αorder␈αto␈αcomplete␈αour␈αdescription␈αof␈αthe␈αfirst␈α
order␈αtheory␈αof␈αLISP␈αwe␈αneed␈αto␈αbe␈αable␈α
to
␈↓ ↓H␈↓represent␈α∞facts␈α∞about␈α
recursively␈α∞defined␈α∞LISP␈α∞functions.␈α
 Given␈α∞a␈α∞recursive␈α∞function␈α
definition
␈↓ ↓H␈↓we␈α
can␈α
form␈α
the␈α
␈↓↓functional equation␈↓␈α
by␈α
replacing␈α
the␈α
"←"␈α
in␈α
the␈α
recursive␈α
function␈α
definition␈αby
␈↓ ↓H␈↓"="␈α⊂and␈α⊂universally␈α⊂quantifying␈α∂over␈α⊂the␈α⊂argument␈α⊂variables.␈α⊂In␈α∂the␈α⊂case␈α⊂of␈α⊂␈↓↓append␈↓␈α⊂which␈α∂is
␈↓ ↓H␈↓defined by

␈↓ ↓H␈↓␈↓ ∧L␈↓↓u * v ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ v ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧u . [␈↓αd␈↓↓␈α∧u * v]␈↓ 

␈↓ ↓H␈↓the corresponding functional equation is

␈↓ ↓H␈↓␈↓¬APPEND: ␈↓               ␈↓↓∀u v: [u * v = ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ v ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧u . [␈↓αd␈↓↓␈α∧u * v]] ␈↓.
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *47


␈↓ ↓H␈↓Sometimes␈αthe␈αfunctional␈αequation␈α characterizes␈αthe␈αfunction␈αcompletely.␈α For␈αthis␈αto␈αbe␈αthe␈αcase
␈↓ ↓H␈↓we␈α∩need␈α⊃to␈α∩know␈α∩that␈α⊃a␈α∩function␈α∩satisfying␈α⊃the␈α∩equation␈α⊃exists␈α∩and␈α∩that␈α⊃it␈α∩is␈α∩unique.␈α⊃This
␈↓ ↓H␈↓essentially␈αreduces␈αto␈αshowing␈αthat␈αthe␈αfunction␈αis␈αtotal.␈α If␈αthe␈αfunction␈αis␈αnot␈αtotal␈αthen␈αwe␈αneed
␈↓ ↓H␈↓the␈α∃additional␈α∃information␈α∃provided␈α∃by␈α∀the␈α∃␈↓↓minimiztion schema.␈↓␈α∃  This␈α∃is␈α∃justified␈α∃by␈α∀the
␈↓ ↓H␈↓semantics␈αof␈αLISP␈αprograms␈αbased␈αon␈αthe␈αuse␈αof␈αfunctionals␈αand␈αfixedpoints.␈α Before␈αproceeding
␈↓ ↓H␈↓with a more detailed discussion of these matters an example is in order.

␈↓ ↓H␈↓        For␈αthe␈αremainder␈αof␈αthis␈αsection␈αwe␈αwill␈αshow␈αhow␈αto␈αuse␈αthe␈αaxiom␈α␈↓¬APPEND␈α␈↓together␈αwith
␈↓ ↓H␈↓the LISP axioms to prove some properties of ␈↓↓append.␈↓  In particular we will show

␈↓ ↓H␈↓␈↓¬NIL-APPEND: ␈↓           ␈↓↓∀v: ␈↓¬NIL␈↓↓ * v = v␈↓

␈↓ ↓H␈↓␈↓¬ISTOT-APPEND: ␈↓         ␈↓↓∀u v: islist [u * v]␈↓

␈↓ ↓H␈↓␈↓¬CAR-APPEND: ␈↓           ␈↓↓∀u v: [¬␈↓αn␈↓↓␈α∧u ⊃ ␈↓αa␈↓↓␈α∧[u * v] = ␈↓αa␈↓↓␈α∧u]␈↓

␈↓ ↓H␈↓␈↓¬CDR-APPEND: ␈↓           ␈↓↓∀u v: [¬␈↓αn␈↓↓␈α∧u ⊃ ␈↓αd␈↓↓␈α∧[u * v] = [␈↓αd␈↓↓␈α∧u] * v]␈↓

␈↓ ↓H␈↓␈↓¬NOTNUL-APPEND: ␈↓        ␈↓↓∀u v: [[¬␈↓αn␈↓↓␈α∧u ∨ ¬␈↓αn␈↓↓␈α∧v] ⊃ ¬␈↓αn␈↓↓␈α∧[u * v]]␈↓

␈↓ ↓H␈↓␈↓¬AASOC-APPEND: ␈↓         ␈↓↓∀u v w: [u * v] * w = u * [v * w]␈↓

␈↓ ↓H␈↓        First we prove ␈↓¬NIL-APPEND. ␈↓ By ␈↓¬APPEND ␈↓and ␈↓¬L5 ␈↓we have

␈↓ ↓H␈↓␈↓ ∧9␈↓↓␈↓¬NIL␈↓↓ * v = ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧␈↓¬NIL␈↓↓ ␈↓αthen␈↓↓ v ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧u . [␈↓αd␈↓↓␈α∧u * v]␈↓ 

␈↓ ↓H␈↓and by ␈↓¬L7 ␈↓this simplifies to  ␈↓↓␈↓¬NIL␈↓↓ * v = v␈↓  as desired.

␈↓ ↓H␈↓        Next we prove ␈↓¬ISTOT-APPEND, ␈↓i.e. that ␈↓↓append␈↓ is total.  For this we use ␈↓¬LISTINDUCTION ␈↓with

␈↓ ↓H␈↓␈↓ ∧|␈↓↓␈↓	F␈↓↓ u ≡ ∀v: islist [u * v]            ␈↓ 

␈↓ ↓H␈↓obtaining the induction axiom

␈↓ ↓H␈↓␈↓ βY␈↓↓[∀u: [␈↓αn␈↓↓␈α∧u ⊃ ∀v: islist [u * v]] ∧                                   ␈↓
␈↓ ↓H␈↓␈↓ ∧↓␈↓↓∀u: [[¬␈↓αn␈↓↓␈α∧u ∧ ∀v: islist [␈↓αd␈↓↓␈α∧u * v]] ⊃ ∀v: islist [u * v]]]␈↓
␈↓ ↓H␈↓␈↓ ∧*␈↓↓⊃ ∀u v: islist [u * v] .                             ␈↓

␈↓ ↓H␈↓The␈αproof␈αthen␈αbreaks␈αinto␈αtwo␈αsteps␈αcorresponding␈αto␈αthe␈αcases␈α␈↓↓␈↓αn␈↓↓␈α∧u␈↓␈αand␈α␈↓↓¬␈↓αn␈↓↓␈α∧u␈↓.␈αIn␈αthe␈αfirst␈αcase␈αwe
␈↓ ↓H␈↓must show

␈↓ ↓H␈↓␈↓ ∧⎇␈↓↓∀u: [␈↓αn␈↓↓␈α∧u ⊃ ∀v: islist [u * v]]      ␈↓ 

␈↓ ↓H␈↓which follows directly from ␈↓¬APPEND ␈↓and ␈↓¬L2. In ␈↓the second case we must show

␈↓ ↓H␈↓␈↓ β}␈↓↓∀u: [[¬␈↓αn␈↓↓␈α∧u ∧ ∀v: islist [␈↓αd␈↓↓␈α∧u * v]] ⊃ ∀v: islist [u * v]] ␈↓. 

␈↓ ↓H␈↓To do this we assume
␈↓ ↓H␈↓48␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓␈↓ ¬α␈↓↓¬␈↓αn␈↓↓␈α∧u ∧ ∀v: islist [␈↓αd␈↓↓␈α∧u * v] .      ␈↓ 

␈↓ ↓H␈↓Then by ␈↓¬L6, ␈↓␈↓¬L10 ␈↓we have ␈↓↓issexp ␈↓αa␈↓↓␈α∧u␈↓ and so by ␈↓¬L9 ␈↓we have

␈↓ ↓H␈↓␈↓ ¬α␈↓↓islist [␈↓αa␈↓↓␈α∧u . [dq u * v]] .         ␈↓ 

␈↓ ↓H␈↓From this and ␈↓¬APPEND, ␈↓since we are in the case ␈↓↓¬␈↓αn␈↓↓␈α∧u␈↓, it follows that

␈↓ ↓H␈↓␈↓ ¬,␈↓↓islist [u * v] .             ␈↓ 

␈↓ ↓H␈↓␈↓¬ISTOT-APPEND ␈↓follows immediately from these two steps and the induction axiom.

␈↓ ↓H␈↓        We now prove ␈↓¬CAR-APPEND. ␈↓ From ␈↓¬APPEND ␈↓we have

␈↓ ↓H␈↓␈↓ ∧|␈↓↓¬␈↓αn␈↓↓␈α∧u ⊃ [u * v = ␈↓αa␈↓↓␈α∧u . [␈↓αd␈↓↓␈α∧u * v]] .␈↓ 

␈↓ ↓H␈↓Now we use ␈↓¬L13 ␈↓and obtain

␈↓ ↓H␈↓␈↓ ¬λ␈↓↓¬␈↓αn␈↓↓␈α∧u ⊃ [␈↓αa␈↓↓␈α∧[u * v] = ␈↓αa␈↓↓␈α∧u]          ␈↓ 

␈↓ ↓H␈↓To␈α
justify␈α
using␈α
␈↓¬L13␈α
␈↓we␈α
need␈α
␈↓↓issexp␈α
␈↓αa␈↓↓␈α∧u␈↓,␈α
␈↓↓islist␈α
␈↓αd␈↓↓␈α∧u␈↓␈α
and␈α
␈↓↓islist␈α
[␈↓αd␈↓↓␈α∧u␈α
*␈α
v]␈↓␈α
under␈α
the␈α∞assumption␈α
that
␈↓ ↓H␈↓␈↓↓¬␈↓αn␈↓↓ u␈↓.␈α∞These␈α∞follow␈α
from␈α∞(␈↓¬L6,␈α∞␈↓␈↓¬L10),␈α
␈↓␈↓¬L12;␈α∞␈↓and␈α∞␈↓¬ISTOT-APPEND␈α
␈↓respectively.␈α∞ ␈↓¬CDR-APPEND␈α∞␈↓is␈α
proved
␈↓ ↓H␈↓similiarly with ␈↓¬L14 ␈↓in place of ␈↓¬L13. ␈↓

␈↓ ↓H␈↓        To prove ␈↓¬NOTNUL-APPEND ␈↓we note first that

␈↓ ↓H␈↓␈↓ ¬↓␈↓↓¬␈↓αn␈↓↓␈α∧u ⊃ ¬␈↓αn␈↓↓␈α∧[u * v]                  ␈↓ 

␈↓ ↓H␈↓follows from ␈↓¬APPEND, ␈↓␈↓¬L6, ␈↓␈↓¬L10, ␈↓␈↓¬L12, ␈↓␈↓¬ISTOT-APPEND, ␈↓and ␈↓¬L15. ␈↓ Second we have

␈↓ ↓H␈↓␈↓ ¬↓␈↓↓[␈↓αn␈↓↓␈α∧u ∧ ¬␈↓αn␈↓↓␈α∧v] ⊃ ¬␈↓αn␈↓↓␈α∧[u * v]         ␈↓ 

␈↓ ↓H␈↓by ␈↓¬APPEND. ␈↓ Combining these two we have the desired result.

␈↓ ↓H␈↓                Finally we prove ␈↓¬ASSOC-APPEND. ␈↓ Again we use ␈↓¬LISTINDUCTION, ␈↓this time with

␈↓ ↓H␈↓␈↓ ∧M␈↓↓␈↓	F␈↓↓ u ≡ ∀v w: [u * v] * w = u * [v * w] ␈↓. 

␈↓ ↓H␈↓First we show

␈↓ ↓H␈↓␈↓ ∧0␈↓↓∀u: [␈↓αn␈↓↓␈α∧u ⊃ ∀v w: [u * v] * w = u * [v * w]] ␈↓. 

␈↓ ↓H␈↓Assuming ␈↓↓␈↓αn␈↓↓␈α∧u␈↓ we have by ␈↓¬APPEND ␈↓that

␈↓ ↓H␈↓␈↓ ∧p␈↓↓[u * v] * w = v * w                  ␈↓ 

␈↓ ↓H␈↓and by ␈↓¬APPEND ␈↓and ␈↓¬ISTOT-APPEND ␈↓that
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *49


␈↓ ↓H␈↓␈↓ ∧p␈↓↓u * [v * w] = v * w                  ␈↓ 

␈↓ ↓H␈↓proving the first step.

␈↓ ↓H␈↓The second step is to show that

␈↓ ↓H␈↓␈↓ α'␈↓↓∀u: [[¬␈↓αn␈↓↓␈α∧u ∧ ∀v w: [␈↓αd␈↓↓␈α∧u * v] * w = [␈↓αd␈↓↓␈α∧u] * [v * w]] ⊃ ∀v w: [u * v] * w = u * [v * w]] ␈↓. 

␈↓ ↓H␈↓We␈α
do␈α∞this␈α
by␈α∞assuming␈α
the␈α∞lefthand␈α
side␈α
of␈α∞the␈α
implication␈α∞and␈α
proving␈α∞a␈α
chain␈α∞of␈α
equalities
␈↓ ↓H␈↓which␈αwill␈αprove␈αthe␈αrighthand␈αside␈αof␈αthe␈αimplication.␈α By␈α␈↓¬APPEND,␈α␈↓␈↓¬NOTNUL-APPEND␈α␈↓and␈α␈↓¬ISTOT-
␈↓ ↓H␈↓¬APPEND ␈↓we have

␈↓ ↓H␈↓␈↓ ∧O␈↓↓[u * v] * w = ␈↓αa␈↓↓␈α∧[u * v] . [␈↓αd␈↓↓␈α∧[u * v] * w]␈↓ 

␈↓ ↓H␈↓and by ␈↓¬CAR-APPEND ␈↓and ␈↓¬CDR-APPEND ␈↓

␈↓ ↓H␈↓␈↓ ∧∀␈↓↓␈↓αa␈↓↓␈α∧[u * v] . [␈↓αd␈↓↓␈α∧[u * v] * w] = ␈↓αa␈↓↓␈α∧u . [[␈↓αd␈↓↓␈α∧u * v] * w] ␈↓. 

␈↓ ↓H␈↓By assumption

␈↓ ↓H␈↓␈↓ ∧.␈↓↓␈↓αa␈↓↓␈α∧u . [[␈↓αd␈↓↓␈α∧u * v] * w] = ␈↓αa␈↓↓␈α∧u . [[␈↓αd␈↓↓␈α∧u] * [v * w]] ␈↓. 

␈↓ ↓H␈↓Finally by ␈↓¬APPEND ␈↓and ␈↓¬ISTOT-APPEND ␈↓since we are in the case ␈↓↓¬␈↓αn␈↓↓␈α∧u␈↓

␈↓ ↓H␈↓␈↓ ∧`␈↓↓␈↓αa␈↓↓␈α∧u . [[␈↓αd␈↓↓␈α∧u] * [v * w]] = u * [v * w] ␈↓. 

␈↓ ↓H␈↓Combining these two steps with the induction axiom we have the desired result.

␈↓ ↓H␈↓        In␈αthe␈αabove␈αproofs␈αwe␈αhave␈αbeen␈αparticularly␈αcareful␈αwith␈αdetails␈αsuch␈αas␈αshowing␈α␈↓↓islist␈αx␈↓
␈↓ ↓H␈↓where␈α
␈↓↓x␈↓␈α
is␈α
an␈α
expression␈α
to␈α
be␈α
substituted␈α∞for␈α
␈↓↓u␈↓␈α
in␈α
some␈α
sentence.␈α
The␈α
proofs␈α
are␈α
in␈α∞fact␈α
fairly
␈↓ ↓H␈↓close␈αto␈αthe␈αformal␈αproofs␈αgiven␈αin␈α Appendix␈αII.␈α
 In␈αlater␈αexamples␈αwe␈αshall␈αbe␈αmore␈αbrief␈αas␈α
the
␈↓ ↓H␈↓reader will be expected to be able to fill in the details.



␈↓ ↓H␈↓8.  ␈↓αFunctionals and Least Fixedpoints. ␈↓


␈↓ ↓H␈↓         Now␈α⊂we␈α⊂will␈α⊂describe␈α⊂a␈α⊂method␈α⊂for␈α⊂determining␈α⊂the␈α⊂function␈α⊂computed␈α⊂by␈α⊃a␈α⊂recursive
␈↓ ↓H␈↓program.␈α∂ This␈α∂will␈α⊂allow␈α∂us␈α∂to␈α⊂justify␈α∂the␈α∂use␈α⊂of␈α∂the␈α∂functional␈α⊂equation␈α∂to␈α∂represent␈α⊂a␈α∂total
␈↓ ↓H␈↓function.␈α
  It␈α
will␈α
also␈α
provide␈α
a␈α
means␈α
of␈α
justifying␈α
the␈α
use␈α
of␈α
the␈α
functional␈α
equation␈α
together
␈↓ ↓H␈↓with␈α∪the␈α∪minimization␈α∪schema␈α∪to␈α∪represent␈α∩partial␈α∪functions␈α∪in␈α∪general.␈α∪ The␈α∪latter␈α∪will␈α∩be
␈↓ ↓H␈↓discussed in a later section.

␈↓ ↓H␈↓        We are interested in recursive programs of the form

␈↓ ↓H␈↓␈↓ ¬-␈↓↓f x ← ␈↓	t␈↓↓[f] x                ␈↓ 
␈↓ ↓H␈↓50␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓where␈α∪␈↓	t␈↓␈α∪is␈α∪a␈α∪computable␈α∪functional.␈α∪ A␈α∪functional␈α∪is␈α∪a␈α∪higher␈α∪order␈α∪function␈α∪which␈α∩takes
␈↓ ↓H␈↓functions␈α
as␈α
arguments␈α
as␈α
well␈α
as␈α
ordinary␈α
arguments.␈α
 The␈α
result␈α
of␈α
applying␈α
a␈α
functional␈α
to␈α
a
␈↓ ↓H␈↓function␈αis␈αa␈αfunction␈αwhich␈αis␈αthen␈αapplied␈αto␈αthe␈αrest␈αof␈αthe␈αarguments.␈α For␈αexample␈αthe␈αLISP
␈↓ ↓H␈↓program␈α␈↓↓mapcar␈↓␈αdefines␈αa␈αfunctional.␈α We␈αwill␈αconsider␈αfunctiionals␈α constructed␈αusing␈αa␈αfunction
␈↓ ↓H␈↓variable␈α
and␈α
a␈α∞set␈α
of␈α
base␈α∞functions␈α
and␈α
predicates␈α
in␈α∞a␈α
manner␈α
similar␈α∞to␈α
the␈α
formation␈α∞of␈α
λ-
␈↓ ↓H␈↓expressions␈α∂(but␈α∂omitting␈α⊂quantifiers).␈α∂  Functionals␈α∂constructed␈α∂in␈α⊂this␈α∂manner␈α∂are␈α⊂called␈α∂␈↓↓term␈↓
␈↓ ↓H␈↓␈↓↓functionals.␈αIn␈↓␈αthe␈αcase␈αof␈αLISP␈αprograms,␈αthe␈αnon-logical␈αfunctions␈αand␈αpredicates␈αare␈α␈↓↓car,␈↓␈α␈↓↓cdr,␈↓
␈↓ ↓H␈↓␈↓↓cons,␈↓ ␈↓↓atom␈↓ and ␈↓↓null.␈↓

␈↓ ↓H␈↓        For example,  for the function ␈↓↓append␈↓ the functional is

␈↓ ↓H␈↓␈↓ ∧!␈↓↓␈↓	t␈↓↓ = λF: λx y: [␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ␈↓αthen␈↓↓ y ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧x . F[␈↓αd␈↓↓␈α∧x,y]]␈↓ 

␈↓ ↓H␈↓or, using infix notation,

␈↓ ↓H␈↓␈↓ ∧λ␈↓↓␈↓	t␈↓↓ = λOP: λx y: [␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧x ␈↓αthen␈↓↓ y ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧x . [␈↓αd␈↓↓␈α∧x OP y]]␈↓. 

␈↓ ↓H␈↓        In␈αorder␈αto␈αsay␈αwhat␈αfunction␈αis␈αcomputed␈αby␈αa␈αrecursive␈αprogram␈αof␈αthe␈αform␈αgiven␈αabove
␈↓ ↓H␈↓we␈α
will␈αneed␈α
to␈αintroduce␈α
the␈αconcepts␈α
of␈α
␈↓↓partial␈↓␈α␈↓↓ordering␈↓␈α
 and␈αof␈α
␈↓↓least␈↓␈α␈↓↓fixedpoints.␈↓␈α
 We␈αgive␈α
here
␈↓ ↓H␈↓only a brief summary.  A more complete discussion can be found in (Manna 1974, Chapter 5).

␈↓ ↓H␈↓        Given␈αa␈αdomain␈αD,␈αwe␈αform␈αa␈αdomain␈αD␈↓∧+␈↓␈αby␈αadjoining␈αthe␈αundefined␈αelement␈α␈↓πT␈↓␈αto␈αD.␈α We
␈↓ ↓H␈↓use␈αupper␈α
case␈αletters␈α
to␈αrange␈α
over␈αD␈↓∧+␈↓␈αwhere␈α
the␈αcorresponding␈α
lower␈αcase␈α
letters␈αrange␈α
over␈αD.
␈↓ ↓H␈↓A partial ordering, ␈↓πb␈↓ (read "less defined than or equal"), on D␈↓∧+␈↓ is defined by

␈↓ ↓H␈↓␈↓ ¬&␈↓↓X ␈↓πb␈↓↓ Y ≡ X = ␈↓πT␈↓↓ ∨ X = Y ␈↓. 

␈↓ ↓H␈↓(Recall␈αthat␈αa␈αpartial␈α
ordering␈αon␈αa␈αset␈αS␈α
is␈αa␈αrelation␈αon␈α(S␈α
␈↓¬x␈α␈↓S)␈αthat␈αis␈αtransitive,␈α
reflexive␈αand
␈↓ ↓H␈↓antisymmetric.)␈α⊂   For␈α⊂example␈α⊃in␈α⊂the␈α⊂domain␈α⊃SE␈↓∧+␈↓␈α⊂we␈α⊂have␈α⊃ ␈↓πT␈↓ ␈↓πb␈↓ ␈↓¬NIL␈↓␈α⊂ and␈α⊂ ␈↓¬NIL␈↓ ␈↓πb␈↓ ␈↓¬NIL␈↓,␈α⊃ but␈α⊂not
␈↓ ↓H␈↓␈↓¬NIL␈↓ ␈↓πb␈↓ (␈↓¬NIL␈↓ . ␈↓¬NIL␈↓).␈α⊂  This␈α⊂partial␈α⊂ordering␈α⊂(sometimes␈α∂called␈α⊂the␈α⊂"flat"␈α⊂partial␈α⊂ordering)␈α⊂is␈α∂indeed
␈↓ ↓H␈↓trivial.␈α A␈αpartial␈αordering␈αcan␈αbe␈αrepresented␈α
by␈αa␈αdiagram␈α in␈αwhich␈αall␈αelements␈αless␈α
than␈αbut
␈↓ ↓H␈↓not␈αequal␈αto␈αa␈αgiven␈αelement␈αare␈α"below"␈αthat␈αelement.␈α For␈αour␈αtrivial␈αordering␈αthe␈α
diagram␈αhas
␈↓ ↓H␈↓only␈αtwo␈α
layers:␈αthe␈α
bottom␈αlayer␈α
consisting␈αof␈α
the␈αsingle␈α
element␈α␈↓πT␈↓␈α
and␈αa␈α
top␈αlayer␈α
consisting␈αof
␈↓ ↓H␈↓the␈αrest.␈α Hence␈αthe␈αname␈α
"flat".␈α Despite␈αthe␈αtrivial␈αnature␈α
of␈αthis␈αparticular␈αpartial␈αordering,␈α
 the
␈↓ ↓H␈↓concept turns out to be very useful.

␈↓ ↓H␈↓        Given␈α∞domains␈α∞D1␈α∞and␈α∞D2␈α∞and␈α∞a␈α∞partial␈α∞function␈α∞␈↓↓f:␈↓␈α∞D1→D2,␈α∞we␈α∞extend␈α∞␈↓↓f␈↓␈α∞to␈α∂a␈α∞ function
␈↓ ↓H␈↓from␈αD1␈↓∧+␈↓␈αto␈α
D2␈↓∧+␈↓␈αby␈αdefining␈α
␈↓↓f ␈↓πT␈↓↓ = ␈↓πT␈↓↓␈↓␈α and,␈αif␈α
␈↓↓f␈↓␈αis␈αundefined␈α
for␈α␈↓↓x␈↓␈αin␈α
D1,␈αthen␈α ␈↓↓f x = ␈↓πT␈↓↓␈↓.␈α(Note␈α
that
␈↓ ↓H␈↓we␈αuse␈αthe␈αsame␈αsymbol␈αto␈αdenote␈αthe␈αundefined␈αelement␈αregardless␈αof␈αdomain.␈αWe␈αshall␈αalso␈αuse
␈↓ ↓H␈↓this␈α⊂symbol␈α⊂to␈α⊂denote␈α⊂a␈α⊂totally␈α⊂undefined␈α⊂function.␈α⊂ Context␈α⊂will␈α⊂make␈α⊂it␈α⊂clear␈α⊂what␈α⊃is␈α⊂being
␈↓ ↓H␈↓denoted␈α∩by␈α∩␈↓πT␈↓.)␈α∩ Other␈α∩extensions␈α∩are␈α∩possible␈α∩but␈α∩we␈α∩will␈α∩not␈α∩consider␈α∩them.␈α∩ We␈α∪will␈α∩not
␈↓ ↓H␈↓distinguish␈α
between␈α∞a␈α
function␈α
and␈α∞its␈α
extension␈α
as␈α∞we␈α
are␈α
considering␈α∞only␈α
one␈α∞extension.␈α
 We
␈↓ ↓H␈↓"lift"␈α∞the␈α∂partial␈α∞orderings␈α∞on␈α∂D1␈↓∧+␈↓␈α∞and␈α∂D2␈↓∧+␈↓␈α∞to␈α∞the␈α∂set␈α∞of␈α∂partial␈α∞functions␈α∞from␈α∂D1␈↓∧+␈↓␈α∞to␈α∂D2␈↓∧+␈↓␈α∞by
␈↓ ↓H␈↓defining

␈↓ ↓H␈↓␈↓ ¬∩␈↓↓f ␈↓πb␈↓↓ g ≡ ∀x in D1: f x ␈↓πb␈↓↓ g x ␈↓. 

␈↓ ↓H␈↓For example if D1 and D2 are the domain SE,
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *51


␈↓ ↓H␈↓␈↓ ¬λ␈↓↓f␈↓β1␈↓↓ = λx: [␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ ␈↓πT␈↓↓]␈↓ 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ β{␈↓↓f␈↓β2␈↓↓ = λx: [␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧x ␈↓αthen␈↓↓ ␈↓αa␈↓↓␈α∧x ␈↓αelse␈↓↓ ␈↓πT␈↓↓] ␈↓. 

␈↓ ↓H␈↓then ␈↓↓f␈↓β1␈↓↓ ␈↓πb␈↓↓ f␈↓β2␈↓↓ ␈↓.

␈↓ ↓H␈↓        The␈α∞partial␈α∞ordering␈α∞on␈α∞the␈α∞function␈α∞domains␈α∞is␈α∞not␈α∞as␈α∞trivial␈α∞as␈α∞that␈α∞on␈α∞the␈α∞underlying
␈↓ ↓H␈↓domains␈α
but␈α
it␈α
is␈α
still␈α
very␈α∞easy␈α
to␈α
work␈α
with.␈α
 A␈α
useful␈α∞concept␈α
here␈α
it␈α
that␈α
of␈α
␈↓↓lub␈↓␈α∞(least␈α
upper
␈↓ ↓H␈↓bound␈αto␈αbe␈αprecise).␈α ␈↓↓lub␈↓␈αacts␈αon␈αsets␈αof␈αfunctions␈αand␈αproduces␈αthe␈αleast␈αfunction␈αin␈αthe␈αdomain
␈↓ ↓H␈↓that␈α
contains␈α
(or␈α
is␈α∞equal␈α
to)␈α
every␈α
function␈α∞in␈α
the␈α
set,␈α
if␈α
such␈α∞a␈α
function␈α
exists.␈α
 A␈α∞special␈α
case
␈↓ ↓H␈↓where ␈↓↓lub␈↓ is always defined is the following.  Let ␈↓↓f␈↓␈↓βi␈↓ be a set of functions satisfying

␈↓ ↓H␈↓␈↓ ¬\␈↓↓f␈↓βi␈↓↓ ␈↓πb␈↓↓ f␈↓βi+1␈↓↓␈↓ for all ␈↓↓i.␈↓ 

␈↓ ↓H␈↓Such␈α∞a␈α
set␈α∞is␈α∞called␈α
a␈α∞␈↓↓chain.␈↓␈α
 The␈α∞␈↓↓lub␈↓␈α∞of␈α
a␈α∞chain␈α
 always␈α∞exists.␈α∞ Call␈α
the␈α∞resulting␈α∞function␈α
␈↓↓f,␈↓
␈↓ ↓H␈↓then␈αwe␈αcan␈αcompute␈α
␈↓↓f␈↓␈αas␈αfollows.␈α If␈α
for␈αsome␈α␈↓↓n␈↓␈α␈↓↓f␈↓βn␈↓↓[x] ≠ ␈↓πT␈↓↓␈↓␈αthen␈α
␈↓↓f[x] = f␈↓βn␈↓↓[x]␈↓.␈α If␈αno␈αsuch␈α
␈↓↓n␈↓␈αexists
␈↓ ↓H␈↓then ␈↓↓f[x] = ␈↓πT␈↓↓␈↓.  This works because of the simple nature of the partial ordering.

␈↓ ↓H␈↓        If␈α␈↓	t␈↓␈αis␈αa␈αfunctional␈αmapping␈αfunctons␈αfrom␈αD1␈αto␈αD2␈αto␈αfunctions␈αof␈αthe␈αsame␈αtype␈αthen␈αa
␈↓ ↓H␈↓function␈α∞␈↓↓f␈↓␈α∞satisfying␈α∞␈↓↓f = ␈↓	t␈↓↓[f]␈↓␈α∞is␈α
 a␈α∞␈↓↓fixedpoint␈↓␈α∞of␈α∞␈↓	t␈↓.␈α∞ If␈α
furthermore␈α∞for␈α∞any␈α∞other␈α∞function␈α∞␈↓↓g␈↓␈α
we
␈↓ ↓H␈↓have␈α
␈↓↓g = ␈↓	t␈↓↓[g] ⊃ f ␈↓πb␈↓↓ g␈↓␈α
 then␈α␈↓↓f␈↓␈α
is␈α
the␈α
␈↓↓least␈↓␈α␈↓↓fixedpoint␈↓␈α
of␈α
␈↓	t␈↓.␈α
 For␈αour␈α
restricted␈α
class␈α
of␈αfunctionals
␈↓ ↓H␈↓the least fixedpoint always exists.   We denote the least fixedpoint of ␈↓	t␈↓ by ␈↓αY␈↓[␈↓	t␈↓].

␈↓ ↓H␈↓        The␈α∩existence␈α∩of␈α⊃␈↓αY␈↓[␈↓	t␈↓]␈α∩is␈α∩due␈α⊃to␈α∩the␈α∩fact␈α⊃that␈α∩our␈α∩functionals␈α⊃have␈α∩some␈α∩very␈α⊃special
␈↓ ↓H␈↓properties.␈α
 One␈α∞such␈α
property␈α∞is␈α
␈↓↓monotonicity.␈↓␈α∞ A␈α
functional,␈α∞␈↓	t␈↓␈α
that␈α∞is␈α
monotonic␈α∞preserves␈α
the
␈↓ ↓H␈↓partial ordering of its function  domain.  In particular, for functions ␈↓↓f␈↓ and ␈↓↓g,␈↓ ␈↓	t␈↓ must satisfy

␈↓ ↓H␈↓␈↓ ¬ε␈↓↓f ␈↓πb␈↓↓ g ⊃ ␈↓	t␈↓↓[f] ␈↓πb␈↓↓ ␈↓	t␈↓↓[g] .            ␈↓ 

␈↓ ↓H␈↓        A␈α
second␈α
propery␈α∞is␈α
␈↓↓continuity.␈↓␈α
 A␈α
continuous␈α∞functional␈α
is␈α
monotonic␈α
and␈α∞must␈α
preserve
␈↓ ↓H␈↓␈↓↓lub␈↓'s␈α∞of␈α∞chains␈α∞of␈α∞functions.␈α∞  In␈α∞particular␈α∞if␈α∞␈↓	t␈↓␈α∞is␈α∞a␈α∞continuous␈α∞functional␈α∞and␈α∞␈↓↓f␈↓βi␈↓↓␈↓␈α∞is␈α∞a␈α∂chain␈α∞of
␈↓ ↓H␈↓functions then the set ␈↓↓␈↓	t␈↓↓[f␈↓βi␈↓↓]␈↓ of functions is also a chain and

␈↓ ↓H␈↓␈↓ ¬A␈↓↓␈↓	t␈↓↓[lub{f␈↓βi␈↓↓}] = lub{␈↓	t␈↓↓[f␈↓βi␈↓↓]}␈↓. 

␈↓ ↓H␈↓        Now we show how to construct ␈↓αY␈↓[␈↓	t␈↓] for a continuous functional ␈↓	t␈↓.  Let

␈↓ ↓H␈↓␈↓ ¬3␈↓↓f␈↓β0␈↓↓ = ␈↓πT␈↓↓␈↓ and ␈↓↓f␈↓βi+1␈↓↓ = ␈↓	t␈↓↓[f␈↓βi␈↓↓] ␈↓. 

␈↓ ↓H␈↓Then

␈↓ ↓H␈↓␈↓ ¬N␈↓↓␈↓πT␈↓↓ = f␈↓β0␈↓↓ ␈↓πb␈↓↓ f␈↓β1␈↓↓ = ␈↓	t␈↓↓[f␈↓β0␈↓↓]␈↓ 

␈↓ ↓H␈↓and, since ␈↓	t␈↓ is monotonic,

␈↓ ↓H␈↓␈↓ ¬\␈↓↓f␈↓βi␈↓↓ ␈↓πb␈↓↓ f␈↓βi+1␈↓↓␈↓ for all ␈↓↓i.␈↓ 
␈↓ ↓H␈↓52␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓Thus␈α
the␈α
functions␈α
␈↓↓f␈↓βi␈↓↓␈↓␈α
form␈α
a␈α
chain,␈α
 ␈↓↓lub{f␈↓βi␈↓↓}␈↓␈α
is␈α
defined,␈α
 and␈α
␈↓↓␈↓αY␈↓↓[␈↓	t␈↓↓] = lub{f␈↓βi␈↓↓}␈↓␈α
.␈α
  Intuitively␈α
one␈αcan
␈↓ ↓H␈↓think␈αof␈αthe␈α␈↓↓f␈↓βi␈↓↓␈↓'s␈αas␈αforming␈αa␈αsequence␈αof␈αsuccessively␈αbetter␈αapproximations␈αto␈αthe␈αfunction␈α␈↓αY␈↓[␈↓	t␈↓].
␈↓ ↓H␈↓What␈αis␈αbeing␈αapproximated␈αis␈αthe␈αdomain␈α
of␈αdefinition.␈α Repeated␈αapplications␈αof␈α␈↓	t␈↓␈αincrease␈α
the
␈↓ ↓H␈↓domain of definition (unless, of course, we have for some ␈↓↓i␈↓ that ␈↓↓f␈↓βi␈↓↓␈↓ = ␈↓αY␈↓[␈↓	t␈↓]).

␈↓ ↓H␈↓        For example if

␈↓ ↓H␈↓␈↓ ∧[␈↓↓␈↓	t␈↓↓ = λf: λx: [␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ f[␈↓αa␈↓↓␈α∧x]] ␈↓ 

␈↓ ↓H␈↓then, for ␈↓↓f␈↓β1␈↓↓␈↓ and ␈↓↓f␈↓β2␈↓↓␈↓ as defined above, we have

␈↓ ↓H␈↓␈↓ ¬$␈↓↓f␈↓β1␈↓↓ = ␈↓	t␈↓↓[␈↓πT␈↓↓]␈↓ and ␈↓↓f␈↓β2␈↓↓ = ␈↓	t␈↓↓[f␈↓β1␈↓↓] ␈↓. 

␈↓ ↓H␈↓The␈α⊂␈↓↓n␈↓␈α∂mentioned␈α⊂above␈α⊂in␈α∂the␈α⊂description␈α⊂of␈α∂how␈α⊂to␈α⊂compute␈α∂␈↓↓lub␈↓␈α⊂of␈α⊂a␈α∂chain␈α⊂of␈α⊂functions␈α∂is
␈↓ ↓H␈↓essentially the number of ␈↓↓car␈↓'s that must be applied to ␈↓↓x␈↓ to reach an atom.

␈↓ ↓H␈↓[A␈α→parenthetical␈α_remark:␈α→ the␈α_notions␈α→of␈α_␈↓↓monotonicity␈↓␈α→and␈α_␈↓↓continuity␈↓␈α→defined␈α→above␈α_are
␈↓ ↓H␈↓generalizations␈α∪of␈α∪those␈α∪encountered␈α∪in␈α∪a␈α∪calculus␈α∪or␈α∪analysis␈α∪course␈α∪in␈α∀mathematics.␈α∪ Such
␈↓ ↓H␈↓generalizations␈αare␈αcommon␈αin␈αthe␈αstudy␈αof␈αtopology␈αand␈αthe␈αabove␈αarguments␈αcan␈αbe␈αformulated
␈↓ ↓H␈↓in a topological framework.]

␈↓ ↓H␈↓        Now␈α∞we␈α∞are␈α∞ready␈α∞to␈α∞define␈α∞the␈α∞function␈α∞computed␈α∞by␈α∞a␈α∞recursive␈α∞program␈α∞and␈α∞to␈α∞show
␈↓ ↓H␈↓how␈α
this␈α∞function␈α
is␈α∞characterized␈α
by␈α∞the␈α
corresponding␈α
functional␈α∞equation␈α
in␈α∞the␈α
case␈α∞of␈α
total
␈↓ ↓H␈↓functions.␈α∂ If␈α∂␈↓	t␈↓␈α∂is␈α∞a␈α∂term functional␈α∂then␈α∂the␈α∂function,␈α∞␈↓↓f,␈↓␈α∂computed␈α∂by␈α∂the␈α∂recursive␈α∞program,
␈↓ ↓H␈↓␈↓↓f x ← ␈↓	t␈↓↓[f] x␈↓  is ␈↓αY␈↓[␈↓	t␈↓].  Thus ␈↓↓f␈↓ satisfies the functional equation

␈↓ ↓H␈↓␈↓ ¬↓␈↓↓∀x: [f x = ␈↓	t␈↓↓[f] x] .                ␈↓ 

␈↓ ↓H␈↓If ␈↓↓f␈↓ is total then ␈↓↓f x ≠ ␈↓πT␈↓↓␈↓ for any ␈↓↓x␈↓ in D1.  This means that for any function ␈↓↓g␈↓

␈↓ ↓H␈↓␈↓ ¬∩␈↓↓f ␈↓πb␈↓↓ g␈↓  iff ␈↓↓f = g .               ␈↓ 

␈↓ ↓H␈↓Thus ␈↓↓f␈↓ is the unique function satisfying the functional equation.

␈↓ ↓H␈↓        In␈α∂the␈α∂case␈α∂that␈α∂␈↓↓f␈↓␈α∂is␈α∂not␈α∂total␈α∂the␈α∂functional␈α∂equation␈α∂is␈α∂not␈α∂sufficient.␈α∂We␈α∂also␈α⊂need␈α∂to
␈↓ ↓H␈↓express␈α∞the␈α
fact␈α∞that␈α
␈↓↓f␈↓␈α∞is␈α∞the␈α
least␈α∞function␈α
satisfying␈α∞this␈α
equation.␈α∞  The␈α∞minimization␈α
schema
␈↓ ↓H␈↓will do that.



␈↓ ↓H␈↓9.  ␈↓αPseudo-logic.␈↓


␈↓ ↓H␈↓         In␈αthis␈αsection␈αwe␈αgive␈αa␈α
method␈αfor␈αhandling␈αrecursively␈αdefined␈αpredicates.␈α Consider␈α
the
␈↓ ↓H␈↓recursive program

␈↓ ↓H␈↓␈↓ β@␈↓↓occur[x, y] ← [x = y] ∨ [¬␈↓αat␈↓↓␈αεy ∧ [occur[x, ␈↓αa␈↓↓␈α∧y] ∨ occur[x, ␈↓αd␈↓↓␈α∧y]]]␈↓. 
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *53


␈↓ ↓H␈↓If␈α⊃we␈α⊃were␈α⊃to␈α⊃treat␈α⊃this␈α⊃program␈α∩in␈α⊃a␈α⊃manner␈α⊃analogous␈α⊃to␈α⊃the␈α⊃functional␈α∩equation␈α⊃method
␈↓ ↓H␈↓described in the last section, we would represent the predicate ␈↓↓occur␈↓ by the sentence

␈↓ ↓H␈↓␈↓ β∃␈↓↓∀x y: [occur[x, y] ≡ [x = y] ∨ [¬␈↓αat␈↓↓␈αεy ∧ [occur[x, ␈↓αa␈↓↓␈α∧y] ∨ occur[x, ␈↓αd␈↓↓␈α∧y]]]]␈↓. 

␈↓ ↓H␈↓However, in order to justify this representation we would have to use partial predicate logic.

␈↓ ↓H␈↓        An␈α
alternate␈αmethod␈α
is␈αto␈α
introduce␈α
a␈αdomain␈α
TV␈αof␈α
truth␈α
values␈αconsisting␈α
of␈αthe␈α
elements
␈↓ ↓H␈↓␈↓¬TT␈α∂␈↓and␈α⊂␈↓¬FF␈α∂␈↓and␈α∂having␈α⊂characteristic␈α∂predicate␈α∂␈↓↓istv.␈↓␈α⊂The␈α∂extension,␈α∂TV␈↓∧+␈↓,␈α⊂of␈α∂TV␈α∂we␈α⊂shall␈α∂call
␈↓ ↓H␈↓ETV.␈α∩It␈α⊃consists␈α∩of␈α⊃the␈α∩elements␈α⊃␈↓¬TT,␈α∩␈↓␈↓¬FF,␈α⊃␈↓␈α∩and␈α⊃␈↓πT␈↓␈α∩and␈α⊃has␈α∩characteristic␈α⊃predicate␈α∩␈↓↓isetv.␈↓␈α⊃ By
␈↓ ↓H␈↓identifying␈α␈↓¬TT␈α
␈↓and␈α␈↓¬FF␈α
␈↓with␈αappropriate␈α
LISP␈αatoms␈α
TV␈αcould␈α
be␈αconsidered␈α
as␈αa␈α
subdomain␈αof
␈↓ ↓H␈↓SE.␈α For␈α
our␈αpurposes␈αit␈α
makes␈αno␈α
difference.␈α We␈αdefine␈α
pseudo-logical␈αoperators␈α
(␈↓↓nnot,␈↓␈α␈↓↓aand,␈↓
␈↓ ↓H␈↓␈↓↓oor)␈↓␈α∂to␈α∂imitate␈α∂the␈α∂logical␈α∞operators␈α∂(¬,␈α∂∧,␈α∂∨)␈α∂and␈α∞pseudo-predicates␈α∂(␈↓↓eeq,␈↓␈α∂␈↓↓aatom)␈↓␈α∂to␈α∂imitate␈α∞the
␈↓ ↓H␈↓basic LISP predicates (=, ␈↓αat␈↓).

␈↓ ↓H␈↓        Now we can imitate the predicate ␈↓↓occur␈↓ by the recursive program

␈↓ ↓H␈↓␈↓ αD␈↓↓occura[x, y] ← [x eeq y] oor [nnot aatom y aand [occura[x, ␈↓αa␈↓↓␈α∧y] oor occura[x, ␈↓αd␈↓↓␈α∧y]]]␈↓ 

␈↓ ↓H␈↓which has the functional equation

␈↓ ↓H␈↓␈↓ α∃␈↓↓∀x y: [occura[x, y] = [x eeq y] oor [nnot aatom y aand [occura[x, ␈↓αa␈↓↓␈α∧y] oor occura[x, ␈↓αd␈↓↓␈α∧y]]]]␈↓. 

␈↓ ↓H␈↓Using this equation and the S-expression induction axiom we can show

␈↓ ↓H␈↓␈↓ ∧O␈↓↓∀x y: istv occura[x, y]                      ␈↓ 

␈↓ ↓H␈↓which is the statement that occura is total.  If we define ␈↓↓occur␈↓ by

␈↓ ↓H␈↓␈↓ ∧G␈↓↓∀x y: [occur[x, y] ≡ occura[x, y] = ␈↓¬TT␈↓↓]   ␈↓ 

␈↓ ↓H␈↓then we can prove the original sentence proposed for representing ␈↓↓occur.␈↓


␈↓ ↓H␈↓αETV axioms

␈↓ ↓H␈↓        We␈α
now␈αgive␈α
the␈αaxioms␈α
for␈αextended␈α
truths␈αvalues␈α
needed␈αto␈α
make␈αthe␈α
above␈αarguments
␈↓ ↓H␈↓and similar ones work.  First the axioms describing the domains TV and ETV.

␈↓ ↓H␈↓␈↓¬B0: ␈↓   ␈↓↓∀P Q: [isetv P ∧ isetv Q]␈↓

␈↓ ↓H␈↓␈↓¬B1: ␈↓   ␈↓↓∀p q: [istv p ∧ istv q]␈↓

␈↓ ↓H␈↓␈↓¬B2: ␈↓   ␈↓↓∀p: isetv p␈↓

␈↓ ↓H␈↓␈↓¬B3: ␈↓   ␈↓↓isetv ␈↓πT␈↓↓ ∧ istv ␈↓¬TT ␈↓↓∧ istv ␈↓¬FF ␈↓↓␈↓

␈↓ ↓H␈↓␈↓¬B4: ␈↓   ␈↓↓∀P: [P = ␈↓¬TT ␈↓↓∨ P = ␈↓¬FF ␈↓↓∨ P = ␈↓πT␈↓↓]␈↓
␈↓ ↓H␈↓54␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓␈↓¬B5: ␈↓   ␈↓↓∀p: [p = ␈↓¬TT ␈↓↓∨ p = ␈↓¬FF␈↓↓]␈↓

␈↓ ↓H␈↓␈↓¬B6: ␈↓   ␈↓↓␈↓¬TT ␈↓↓≠ ␈↓¬FF ␈↓↓∧ ␈↓¬TT ␈↓↓≠ ␈↓πT␈↓↓ ∧ ␈↓¬FF ␈↓↓≠ ␈↓πT␈↓↓␈↓

␈↓ ↓H␈↓        Next␈α∪the␈α∪axioms␈α∪defining␈α∪the␈α∪functions␈α∪on␈α∪ETV␈α∪corresponding␈α∪to␈α∪the␈α∩pseudo-logical
␈↓ ↓H␈↓operators and pseudo-predicates.

␈↓ ↓H␈↓␈↓¬B7: ␈↓   ␈↓↓∀P: [nnot P = ␈↓αif␈↓↓ [P = ␈↓πT␈↓↓] ␈↓αthen␈↓↓ ␈↓πT␈↓↓ ␈↓αelse␈↓↓ ␈↓αif␈↓↓ [P = ␈↓¬TT␈↓↓] ␈↓αthen␈↓↓ ␈↓¬FF ␈↓↓␈↓αelse␈↓↓ ␈↓¬TT␈↓↓]␈↓

␈↓ ↓H␈↓␈↓¬B8: ␈↓   ␈↓↓∀P Q: [P aand Q = ␈↓αif␈↓↓ [P = ␈↓πT␈↓↓] ␈↓αthen␈↓↓ ␈↓πT␈↓↓ ␈↓αelse␈↓↓ if [P = ␈↓¬TT␈↓↓] ␈↓αthen␈↓↓ Q ␈↓αelse␈↓↓ ␈↓¬FF␈↓↓]␈↓

␈↓ ↓H␈↓␈↓¬B9: ␈↓   ␈↓↓∀P Q: [P oor Q = ␈↓αif␈↓↓ [P = ␈↓πT␈↓↓] ␈↓αthen␈↓↓ ␈↓πT␈↓↓ ␈↓αelse␈↓↓ ␈↓αif␈↓↓ [P = ␈↓¬TT␈↓↓] ␈↓αthen␈↓↓ ␈↓¬TT ␈↓↓␈↓αelse␈↓↓ Q]␈↓

␈↓ ↓H␈↓␈↓¬B10: ␈↓  ␈↓↓∀X Y: [X eeq Y] = ␈↓αif␈↓↓ [¬issexp X ∨ ¬issexp Y] ␈↓αthen␈↓↓ ␈↓πT␈↓↓ ␈↓αelse␈↓↓ ␈↓αif␈↓↓ [X = Y] ␈↓αthen␈↓↓ ␈↓¬TT ␈↓↓␈↓αelse␈↓↓ ␈↓¬FF␈↓↓]␈↓

␈↓ ↓H␈↓␈↓¬B11: ␈↓  ␈↓↓∀X: [aatom X = ␈↓αif␈↓↓ [¬issexp X] ␈↓αthen␈↓↓ ␈↓πT␈↓↓ ␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ ␈↓¬TT ␈↓↓␈↓αelse␈↓↓ ␈↓¬FF␈↓↓]␈↓

␈↓ ↓H␈↓        Finally a conditional function which takes elements of ETV as its first argument.

␈↓ ↓H␈↓␈↓¬B12: ␈↓  ␈↓↓∀P X Y: [iif[P, X, Y] = ␈↓αif␈↓↓ [P = ␈↓πT␈↓↓] ␈↓αthen␈↓↓ ␈↓πT␈↓↓ ␈↓αelse␈↓↓ ␈↓αif␈↓↓ [P = ␈↓¬TT␈↓↓] ␈↓αthen␈↓↓ X ␈↓αelse␈↓↓ Y]␈↓


␈↓ ↓H␈↓αETV lemmas

␈↓ ↓H␈↓        We␈α
now␈αgive␈α
some␈α
lemmas␈αwhich␈α
show␈αthat␈α
the␈α
pseudo-␈αoperators␈α
and␈α
predicates␈αbehave
␈↓ ↓H␈↓as advertised.  First we need to know that the functions map into ETV.

␈↓ ↓H␈↓␈↓¬ETVNNOT: ␈↓              ␈↓↓∀P: isetv nnot P␈↓

␈↓ ↓H␈↓␈↓¬ETVAAND: ␈↓              ␈↓↓∀P Q: isetv [P aand Q]␈↓

␈↓ ↓H␈↓␈↓¬ETVOOR: ␈↓               ␈↓↓∀P Q: isetv [P oor Q]␈↓

␈↓ ↓H␈↓␈↓¬ETVEEQ: ␈↓               ␈↓↓∀X Y: isetv [X eeq Y]␈↓

␈↓ ↓H␈↓␈↓¬ETVAATOM: ␈↓             ␈↓↓∀X: isetv aatom X␈↓

␈↓ ↓H␈↓        These␈α
lemmas␈α
are␈α
all␈α
a␈α
direct␈α
consequence␈α
of␈α
the␈α
function␈α
definitions␈α
and␈α
the␈α
axioms␈α
␈↓¬B0,␈α
␈↓␈↓¬B2
␈↓ ↓H␈↓¬␈↓and ␈↓¬B3. ␈↓

␈↓ ↓H␈↓        Next␈αare␈αsome␈αlemmas␈αstating␈αthat␈αthe␈αfunctions␈αdefined␈αabove␈αare␈αtotal␈αwhen␈αrestricted␈αto
␈↓ ↓H␈↓the domains TV or SE as appropriate.

␈↓ ↓H␈↓␈↓¬TVNNOT: ␈↓               ␈↓↓∀p: istv nnot p␈↓

␈↓ ↓H␈↓␈↓¬TVAAND: ␈↓               ␈↓↓∀p q: istv [p aand q]␈↓

␈↓ ↓H␈↓␈↓¬TVOOR: ␈↓                ␈↓↓∀p q: istv [p oor q]␈↓
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *55


␈↓ ↓H␈↓␈↓¬TVEEQ: ␈↓                ␈↓↓∀x y: istv [x eeq y]␈↓

␈↓ ↓H␈↓␈↓¬TVAATOM: ␈↓              ␈↓↓∀x: istv atom x␈↓

␈↓ ↓H␈↓        These lemmas follow from the function definitions and the axioms ␈↓¬L1, ␈↓ ␈↓¬B1, ␈↓␈↓¬B3, ␈↓␈↓¬B5 ␈↓and ␈↓¬B6. ␈↓

␈↓ ↓H␈↓        Next␈α∩are␈α∩some␈α∪lemmas␈α∩which␈α∩show␈α∪that␈α∩the␈α∩functions␈α∪do␈α∩indeed␈α∩imitate␈α∪their␈α∩logical
␈↓ ↓H␈↓counterparts.

␈↓ ↓H␈↓␈↓¬EQNNOT: ␈↓               ␈↓↓∀p: [nnot p = ␈↓¬TT ␈↓↓≡ ¬[p = ␈↓¬TT␈↓↓]]␈↓

␈↓ ↓H␈↓␈↓¬EQAAND: ␈↓               ␈↓↓∀p q: [p aand q = ␈↓¬TT ␈↓↓≡ p = ␈↓¬TT ␈↓↓∧ q = ␈↓¬TT␈↓↓]␈↓

␈↓ ↓H␈↓␈↓¬EQOOR: ␈↓                ␈↓↓∀p q: [p oor q = ␈↓¬TT ␈↓↓≡ p = ␈↓¬TT ␈↓↓∨ q = ␈↓¬TT␈↓↓]␈↓

␈↓ ↓H␈↓␈↓¬EQEEQ: ␈↓                ␈↓↓∀x y: [x eeq y = ␈↓¬TT ␈↓↓≡ x = y]␈↓

␈↓ ↓H␈↓␈↓¬EQAATOM: ␈↓              ␈↓↓∀x: [aatom x = ␈↓¬TT ␈↓↓≡ ␈↓αat␈↓↓␈αεx]␈↓

␈↓ ↓H␈↓        These␈αlemmas␈αcan␈αall␈αbe␈αproved␈αby␈α
simple␈αcase␈αanalysis.␈α We␈αprove␈α␈↓¬EQAAND␈αand␈α
␈↓␈↓¬EQEEQ␈α␈↓as
␈↓ ↓H␈↓examples.  By ␈↓¬B1, ␈↓␈↓¬B5, ␈↓␈↓¬B6, ␈↓and ␈↓¬B8 ␈↓ we have

␈↓ ↓H␈↓␈↓ ∧I␈↓↓p aand q = ␈↓αif␈↓↓ [p=␈↓¬TT] ␈↓↓␈↓αthen␈↓↓ q ␈↓αelse␈↓↓ ␈↓¬FF ␈↓↓    ␈↓ 

␈↓ ↓H␈↓and ␈↓¬EQAAND ␈↓follows immediately using ␈↓¬B6. ␈↓ By ␈↓¬L1 ␈↓and ␈↓¬B10 ␈↓

␈↓ ↓H␈↓␈↓ ∧T␈↓↓x eeq y = ␈↓αif␈↓↓ [x = y] ␈↓αthen␈↓↓ ␈↓¬TT ␈↓↓␈↓αelse␈↓↓ ␈↓¬FF ␈↓↓   ␈↓ 

␈↓ ↓H␈↓and ␈↓¬EQEEQ ␈↓follows using ␈↓¬B6. ␈↓

␈↓ ↓H␈↓        Finally we give some lemmas that will be useful in later examples.

␈↓ ↓H␈↓␈↓¬TVNOTATM: ␈↓             ␈↓↓∀x y: istv [nnot aatom x aand nnot aatom y]␈↓

␈↓ ↓H␈↓␈↓¬EQNOTATM: ␈↓             ␈↓↓∀x y: [[nnot aatom x aand nnot aatom y] = ␈↓¬TT ␈↓↓≡ [¬␈↓αat␈↓↓␈αεx ∧ ¬␈↓αat␈↓↓␈αεy]]␈↓

␈↓ ↓H␈↓        ␈↓¬TVNOTATM␈α␈↓follows␈αfrom␈α␈↓¬TVNNOT,␈α␈↓␈↓¬TVAATOM,␈α␈↓and␈α␈↓¬TVAAND.␈α␈↓␈α␈↓¬EQNOTATM␈α␈↓follows␈αfrom␈α␈↓¬EQAAND
␈↓ ↓H␈↓¬␈↓and ␈↓↓∀x: nnot aatom x = ␈↓¬TT␈↓↓ ≡ ¬␈↓αat␈↓↓␈αεx␈↓.  The latter follows from ␈↓¬TVAATM, ␈↓ ␈↓¬EQNNOT ␈↓and ␈↓¬EQAATOM. ␈↓

␈↓ ↓H␈↓␈↓¬POORF: ␈↓                ␈↓↓∀P: [P oor ␈↓¬FF ␈↓↓= P]␈↓

␈↓ ↓H␈↓␈↓¬FAANDQ: ␈↓               ␈↓↓∀Q: [␈↓¬FF ␈↓↓aand Q = ␈↓¬FF␈↓↓]␈↓

␈↓ ↓H␈↓        ␈↓¬POORF␈α
␈↓follows␈αfrom␈α
␈↓¬B9␈α␈↓by␈α
case␈α
analysis␈αusing␈α
␈↓¬B4␈α␈↓and␈α
␈↓¬B6.␈α
␈↓␈α␈↓¬FAANDQ␈α
␈↓follows␈α by␈α
simplification
␈↓ ↓H␈↓of ␈↓¬B8 ␈↓using ␈↓¬B6. ␈↓

␈↓ ↓H␈↓        A formal proof of many of the above lemmas is included in  Appendix II.
␈↓ ↓H␈↓56␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓α␈↓ εExercise.

␈↓ ↓H␈↓        Prove the statements made about ␈↓↓occur␈↓ and ␈↓↓occura.␈↓  Namely show

␈↓ ↓H␈↓␈↓ ∧O␈↓↓∀x y: istv occura[x, y]                      ␈↓ 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ β∃␈↓↓∀x y: [occur[x, y] ≡ [x = y] ∨ [¬␈↓αat␈↓↓␈αεy ∧ [occur[x, ␈↓αa␈↓↓␈α∧y] ∨ occur[x, ␈↓αd␈↓↓␈α∧y]]]]␈↓. 

␈↓ ↓H␈↓using the definitions

␈↓ ↓H␈↓␈↓ α_␈↓↓∀x y: [occura[x, y] = [x eeq y] oor [nnot aatom y aand [occura[x, ␈↓αa␈↓↓␈α∧y] oor occura[x, ␈↓αd␈↓↓␈α∧y]]]]␈↓ 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ ∧F␈↓↓∀x y: [occur[x, y] ≡ occura[x, y] = ␈↓¬TT␈↓↓].  ␈↓ 



␈↓ ↓H␈↓10.  ␈↓αAn Extended Example.␈↓


␈↓ ↓H␈↓         As␈α
a␈α
non␈α∞trivial␈α
application␈α
of␈α∞the␈α
techniques␈α
described␈α
in␈α∞the␈α
previous␈α
sections,␈α∞we␈α
will
␈↓ ↓H␈↓give␈αa␈αproof␈αof␈αcorrectness␈αof␈αthe␈αpredicate␈α␈↓↓samefringe␈↓␈αwhich␈αhas␈αbeen␈αproposed␈αas␈αa␈αsolution␈αof
␈↓ ↓H␈↓the␈α∪SAMEFRINGE␈α∀problem.␈α∪ This␈α∀is␈α∪the␈α∀problem␈α∪of␈α∀determining␈α∪whether␈α∀or␈α∪not␈α∀two␈α∪S-
␈↓ ↓H␈↓expressions␈α
have␈α
the␈αsame␈α
fringe␈α
using␈αa␈α
minimum␈α
of␈αspace.␈α
 (We␈α
will␈αbe␈α
concerned␈α
only␈αwith␈α
the
␈↓ ↓H␈↓correctness of ␈↓↓samefringe␈↓ since the efficiency is not an ␈↓↓extensional␈↓ property).

␈↓ ↓H␈↓        The␈α
fringe␈α
of␈α
an␈αS-expression,␈α
␈↓↓x,␈↓␈α
is␈α
a␈α
list␈αof␈α
atoms␈α
in␈α
the␈α
order␈αthat␈α
they␈α
occur␈α
in␈α␈↓↓x.␈↓␈α
 Thus
␈↓ ↓H␈↓the␈α∂fringe␈α⊂of␈α∂␈↓¬A␈α⊂␈↓is␈α∂␈↓¬(A)␈α⊂␈↓and␈α∂the␈α∂fringe␈α⊂of␈α∂␈↓¬((A . B) . (C . D))␈↓␈α⊂is␈α∂␈↓¬(A B C D)␈↓.␈α⊂ The␈α∂LISP␈α⊂program␈α∂for
␈↓ ↓H␈↓computing the fringe of an S-expression is

␈↓ ↓H␈↓␈↓ β↑␈↓↓fringe x ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ <x> ␈↓αelse␈↓↓ [fringe ␈↓αa␈↓↓␈α∧x] * [fringe ␈↓αd␈↓↓␈α∧x]␈↓ 

␈↓ ↓H␈↓The predicate ␈↓↓samefringe␈↓ is computed by the LISP program

␈↓ ↓H␈↓␈↓ βλ␈↓↓samefringe[x, y] ← x = y ∨ [¬␈↓αat␈↓↓␈αεx ∧ ¬␈↓αat␈↓↓␈αεy ∧ same[gopher x, gopher y]]␈↓ 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ ∧4␈↓↓same[x, y] ← ␈↓αa␈↓↓␈α∧x = ␈↓αa␈↓↓␈α∧y ∧ samefringe[␈↓αd␈↓↓␈α∧x, ␈↓αd␈↓↓␈α∧y]␈↓ 

␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ β↑␈↓↓gopher x ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧x ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ gopher [␈↓αaa␈↓↓␈α∧x . [␈↓αda␈↓↓␈α∧x . ␈↓αd␈↓↓␈α∧x]]␈↓ 

␈↓ ↓H␈↓Using the method of the previous section we define an imitation of ␈↓↓samefringe␈↓ by
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *57


␈↓ ↓H␈↓␈↓ β∃␈↓↓samefringea[x, y] ← [x eeq y] oor [[nnot aatom x aand nnot aatom y]␈↓
␈↓ ↓H␈↓␈↓ ∧2␈↓↓             aand samea[gopher x, gopher y]]␈↓

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓ βz␈↓↓samea[x, y] ← [␈↓αa␈↓↓␈α∧x eeq ␈↓αa␈↓↓␈α∧y] aand samefringea[␈↓αd␈↓↓␈α∧x, ␈↓αd␈↓↓␈α∧y]␈↓ 

␈↓ ↓H␈↓Thus we have the functional equations

␈↓ ↓H␈↓␈↓¬FRINGE: ␈↓       ␈↓↓∀x: [fringe x = ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ <x> ␈↓αelse␈↓↓ [fringe ␈↓αa␈↓↓␈α∧x] * [fringe ␈↓αd␈↓↓␈α∧x]]␈↓


␈↓ ↓H␈↓␈↓¬SAMEFRINGEA: ␈↓  ␈↓↓∀x y: [samefringea[x, y] = [x eeq y] oor [[nnot aatom x aand nnot aatom y]␈↓
␈↓ ↓H␈↓                                                        ␈↓↓aand samea[gopher x, gopher y]]]␈↓

␈↓ ↓H␈↓␈↓¬SAMEA: ␈↓        ␈↓↓∀x y: [samea[x, y] = [␈↓αa␈↓↓␈α∧x eeq ␈↓αa␈↓↓␈α∧y] aand samefringea[␈↓αd␈↓↓␈α∧x, ␈↓αd␈↓↓␈α∧y]]␈↓

␈↓ ↓H␈↓␈↓¬SAMEFRINGE: ␈↓   ␈↓↓∀x y: [samefringe[x, y] ≡ samefringea[x, y] = ␈↓¬TT␈↓↓]␈↓

␈↓ ↓H␈↓␈↓¬SAME: ␈↓         ␈↓↓∀x y: [same[x, y] ≡ samea[x, y] = ␈↓¬TT␈↓↓]␈↓

␈↓ ↓H␈↓␈↓¬GOPHER: ␈↓       ␈↓↓∀x: [gopher x = ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧x ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ gopher [␈↓αaa␈↓↓␈α∧x . [␈↓αda␈↓↓␈α∧x . ␈↓αd␈↓↓␈α∧x]]]␈↓


␈↓ ↓H␈↓        In␈αorder␈α
to␈αprove␈α
that␈α␈↓↓samefringea␈↓␈α
is␈αtotal␈α
we␈αwill␈α
need␈αthe␈α
fact␈αthat␈α
␈↓↓samea␈↓␈αmaps␈αinto␈α
ETV.
␈↓ ↓H␈↓This␈α is␈α because␈α in␈α the␈α∨case␈α ␈↓↓x␈↓␈α is␈α an␈α atom␈α or␈α∨␈↓↓y␈↓␈α is␈α an␈α atom␈α we␈α must␈α∨have
␈↓ ↓H␈↓␈↓↓isetv samea[gopher x, gopher y]␈↓␈α⊂in␈α∂order␈α⊂to␈α∂use␈α⊂the␈α⊂definition␈α∂of␈α⊂␈↓↓aand␈↓␈α∂even␈α⊂though␈α⊂the␈α∂actual
␈↓ ↓H␈↓value␈αis␈αirrelevant.␈αThere␈αare␈αseveral␈αways␈αto␈αdo␈α
this.␈α One␈αwould␈αbe␈αto␈αdefine␈α␈↓↓gopher␈↓␈αof␈αan␈α
atom
␈↓ ↓H␈↓to␈αbe␈α␈↓πT␈↓,␈αand␈αhave␈αan␈α
axiom␈αstating␈αthat␈α␈↓↓samea␈↓␈αproduces␈α␈↓πT␈↓␈α
if␈αeither␈αargument␈αis␈α␈↓πT␈↓.␈α Another␈αis␈α
to
␈↓ ↓H␈↓take␈α
as␈αpart␈α
of␈αthe␈α
definition␈α
of␈α␈↓↓samea␈↓␈α
that␈αit␈α
maps␈α
into␈αETV,␈α
without␈αstating␈α
for␈αwhat␈α
arguments
␈↓ ↓H␈↓it␈α
actually␈α
produces␈α
␈↓πT␈↓.␈α
 We␈α
have␈α
chosen␈α
the␈αlatter␈α
option␈α
as␈α
it␈α
seems␈α
cleaner.␈α
 Thus␈α
we␈α
add␈αthe
␈↓ ↓H␈↓axiom

␈↓ ↓H␈↓␈↓¬ETVSAMEA: ␈↓     ␈↓↓∀X Y  isetv samea[X, Y]␈↓

␈↓ ↓H␈↓        The goal is to prove the following three statements:

␈↓ ↓H␈↓␈↓¬THM1: ␈↓         ␈↓↓∀x y: istv samefringea[x, y]␈↓

␈↓ ↓H␈↓␈↓¬THM2: ␈↓         ␈↓↓∀x y: [samefringe[x, y] ≡ [x = y] ∨ [[¬␈↓αat␈↓↓␈αεx ∧ ¬␈↓αat␈↓↓␈αεy] ∧ same[gophe x, gopher y]]␈↓

␈↓ ↓H␈↓␈↓¬THM3: ␈↓         ␈↓↓∀x y: [samefringe[x, y] ≡ fringe x = fringe y]␈↓

␈↓ ↓H␈↓        ␈↓¬THM1␈α␈↓says␈αthat␈α␈↓↓samefringea␈↓␈αis␈αtotal,␈α␈↓¬THM2␈α␈↓says␈αthat␈α␈↓↓samefringe␈↓␈αas␈αdefined␈αvia␈αits␈αimitatiom
␈↓ ↓H␈↓satisfies the intended equivalence, and ␈↓¬THM3 ␈↓says that ␈↓↓samefringe␈↓ is correct.

␈↓ ↓H␈↓        Due␈α⊂to␈α⊂the␈α⊂complicated␈α⊂form␈α∂of␈α⊂the␈α⊂recursion␈α⊂defining␈α⊂␈↓↓samefringe,␈↓␈α⊂simple␈α∂S-expression
␈↓ ↓H␈↓58␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓induction␈α∞is␈α∞not␈α∞adequate␈α∞to␈α∞prove␈α∞the␈α∞above␈α
theorems.␈α∞ Therefore␈α∞if␈α∞we␈α∞wish␈α∞to␈α∞carry␈α∞out␈α
the
␈↓ ↓H␈↓proof␈αby␈α
structural␈αinduction␈α
we␈αmust␈α
find␈αan␈αaxiom␈α
schema␈αappropriate␈α
for␈αthe␈α
problem.␈α One
␈↓ ↓H␈↓way␈αis␈αto␈αuse␈αinduction␈αon␈αthe␈αsize␈αof␈αthe␈αS-expressions␈αinvolved.␈α The␈αsize␈αof␈αan␈αS-expression␈α␈↓↓x␈↓
␈↓ ↓H␈↓is the number of atoms occuring in ␈↓↓x␈↓ and is computed by the LISP program

␈↓ ↓H␈↓␈↓ ∧2␈↓↓size x ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ 1 ␈↓αelse␈↓↓ size ␈↓αa␈↓↓␈α∧x + size ␈↓αd␈↓↓␈α∧x␈↓ 

␈↓ ↓H␈↓␈↓↓size␈↓␈α
provides␈α
a␈α
mapping␈α
of␈α
S-expressions␈α
into␈α
the␈α
domain␈α
of␈α
natural␈α
numbers␈α
and␈α
allows␈α
us␈α
to
␈↓ ↓H␈↓transform␈α
the␈α
problem␈αinto␈α
one␈α
of␈α
natural␈αnumber␈α
induction.␈α
 In␈α
particular␈αwe␈α
will␈α
take␈α
for␈αthe
␈↓ ↓H␈↓axiom schema, the course of values induction schema

␈↓ ↓H␈↓␈↓¬NUMBINDUCTION: ␈↓        ␈↓↓∀n: [∀m: [m < n ⊃ ␈↓	F␈↓↓ m] ⊃ ␈↓	F␈↓↓ n] ⊃ ∀n: ␈↓	F␈↓↓ n␈↓

␈↓ ↓H␈↓with

␈↓ ↓H␈↓␈↓ ∧∨␈↓↓␈↓	F␈↓↓ n ≡ ∀x y: [size x + size y = n ⊃ THM[x, y]]␈↓ 

␈↓ ↓H␈↓where

␈↓ ↓H␈↓␈↓¬THM: ␈↓                  ␈↓↓∀x y: [THM[x, y] ≡ THM1[x, y] ∧ THM2[x, y] ∧ THM3[x, y]]␈↓.

␈↓ ↓H␈↓        In␈α
order␈α
to␈α
use␈α
the␈α
␈↓¬NUMBINDUCTION␈α
␈↓␈α
axiom␈α
we␈α
will␈α
need␈α
the␈α
functional␈α
equation␈α
for␈α␈↓↓size␈↓␈α
and
␈↓ ↓H␈↓some␈α∞properties␈α∞of␈α∞the␈α∞natural␈α∞numbers.␈α∞ The␈α∞characteristic␈α∞predicate␈α∞of␈α∞the␈α∞domain␈α∞of␈α∞natural
␈↓ ↓H␈↓numbers is ␈↓↓natnum␈↓ and we add to our list of axioms the following:

␈↓ ↓H␈↓␈↓¬NUMVAR: ␈↓       ␈↓↓∀k l m n: [natnum k ∧ natnum l ∧ natnum m ∧ natnum n]␈↓

␈↓ ↓H␈↓␈↓¬ONE: ␈↓          ␈↓↓natnum 1␈↓

␈↓ ↓H␈↓␈↓¬ISTOT-PLUS: ␈↓   ␈↓↓∀m n: natnum [m + n]␈↓

␈↓ ↓H␈↓␈↓¬ASSOC: ␈↓        ␈↓↓∀l m n: l + [m + n] = [l + m] + n␈↓

␈↓ ↓H␈↓␈↓¬ORDER-PLUS: ␈↓   ␈↓↓∀k l m n: [[k < l ∧ m < n] ⊃ k + m < l + n]␈↓

␈↓ ↓H␈↓␈↓¬ORDER: ␈↓        ␈↓↓∀n: n < 1 + n␈↓

␈↓ ↓H␈↓␈↓¬SIZE: ␈↓         ␈↓↓∀x: [size x = ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ 1 ␈↓αelse␈↓↓ size ␈↓αa␈↓↓␈α∧x + size ␈↓αd␈↓↓␈α∧x]␈↓

␈↓ ↓H␈↓Here␈αwe␈αhave␈αnot␈αattempted␈αto␈αaxiomatize␈αthe␈αnatural␈αnumbers,␈αbut␈αsimply␈αhave␈αtaken␈αas␈α
axioms
␈↓ ↓H␈↓those properties needed for the present problem.

␈↓ ↓H␈↓        Now␈α∞to␈α
proceed␈α∞with␈α
the␈α∞proof.␈α
 In␈α∞addition␈α
to␈α∞the␈α
lemmas␈α∞ about␈α
␈↓↓append␈↓␈α∞and␈α∞the␈α
ETV
␈↓ ↓H␈↓lemmas␈α⊂proved␈α∂in␈α⊂earlier␈α⊂sections,␈α∂we␈α⊂will␈α⊂need␈α∂some␈α⊂lemmas␈α⊂about␈α∂␈↓↓gopher,␈↓␈α⊂␈↓↓fringe,␈↓␈α⊂␈↓↓size␈↓␈α∂and
␈↓ ↓H␈↓combinations thereof. They are

␈↓ ↓H␈↓␈↓¬GOOD-GOPHER: ␈↓  ␈↓↓∀x: [¬␈↓αat␈↓↓␈αεx ⊃ [issexp gopher x ∧ issexp ␈↓αa␈↓↓␈α∧gopher x ∧ issexp ␈↓αd␈↓↓␈α∧gopher x]]␈↓
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *59


␈↓ ↓H␈↓␈↓¬GOOD-FRINGE: ␈↓  ␈↓↓∀x: [issexp fringe x ∧ ¬␈↓αat␈↓↓␈αεfringe x]␈↓

␈↓ ↓H␈↓␈↓¬FRINGE-ATM: ␈↓   ␈↓↓∀x y: [[␈↓αat␈↓↓␈αεx ∨ ␈↓αat␈↓↓␈αεy] ⊃ [fringe x = fringe y ≡ x = y]]␈↓

␈↓ ↓H␈↓␈↓¬FRINGE-GOPHER: ␈↓␈↓↓∀x: [¬␈↓αat␈↓↓␈αεx ⊃ [␈↓αa␈↓↓␈α∧fringe x = ␈↓αa␈↓↓␈α∧gopher x] ∧ [␈↓αd␈↓↓␈α∧fringe x = fringe ␈↓αd␈↓↓␈α∧gopher x]]␈↓

␈↓ ↓H␈↓␈↓¬ISTOT-SIZE: ␈↓   ␈↓↓∀x: natnum size x␈↓

␈↓ ↓H␈↓␈↓¬SIZE-GOPHER: ␈↓  ␈↓↓∀x y: [[¬␈↓αat␈↓↓␈αεx ∧ ¬␈↓αat␈↓↓␈αεy] ⊃ [size ␈↓αd␈↓↓␈α∧gopher x +size ␈↓αd␈↓↓␈α∧gopher y]  < [size x + size y]]␈↓

␈↓ ↓H␈↓        We␈α⊂will␈α⊃give␈α⊂only␈α⊃a␈α⊂brief␈α⊂indication␈α⊃of␈α⊂the␈α⊃proof␈α⊂of␈α⊂these␈α⊃lemmas.␈α⊂ Formal␈α⊃proofs␈α⊂are
␈↓ ↓H␈↓contained in  Appendix II.

␈↓ ↓H␈↓        The␈αkey␈αidea␈αin␈αproving␈αthings␈αabout␈α␈↓↓gopher␈↓␈αis␈αto␈αfirst␈αprove␈αproperties␈αof␈α␈↓↓gopher[x . y]␈↓␈αas
␈↓ ↓H␈↓gopher␈αis␈α
only␈αdefined␈αfor␈α
non␈αatoms␈α
and␈αevery␈αnon␈α
atom␈αcan␈α
be␈αexpressed␈αas␈α
␈↓↓x . y␈↓␈αfor␈αsuitable␈α
␈↓↓x␈↓
␈↓ ↓H␈↓and␈α␈↓↓y.␈↓␈αFor␈αthis␈α
purpose␈αwe␈αstart␈αwith␈α
some␈αuseful␈αfacts␈αderived␈α
from␈α␈↓¬GOPHER,␈α␈↓␈α␈↓¬FRINGE,␈α
␈↓␈↓¬SIZE␈α␈↓and
␈↓ ↓H␈↓the LISP axioms.

␈↓ ↓H␈↓␈↓¬GOPHER-CONS-ATM: ␈↓      ␈↓↓∀x y: [␈↓αa␈↓↓␈α∧x ⊃ gopher[x . y] = [x . y]]␈↓

␈↓ ↓H␈↓␈↓¬GOPHER-CONS-NOTATM: ␈↓   ␈↓↓∀x y: [¬␈↓αa␈↓↓␈α∧x ⊃ gopher[x . y] = gopher[␈↓αa␈↓↓␈α∧x. [␈↓αd␈↓↓␈α∧x . y]]]␈↓

␈↓ ↓H␈↓␈↓¬FRINGE-CONS: ␈↓          ␈↓↓∀x y: [fringe[x . y] = fringe x * fringe y]␈↓

␈↓ ↓H␈↓␈↓¬SIZE-CONS: ␈↓            ␈↓↓∀x y:  [size[x . y] = size x + size y]␈↓

␈↓ ↓H␈↓        To prove ␈↓¬GOOD-GOPHER ␈↓first prove, by a straight forward use of ␈↓¬SEXPINDUCTION, ␈↓that

␈↓ ↓H␈↓                ␈↓↓∀x y: [issexp gopher[x . y] ∧ ¬␈↓αat␈↓↓␈αεgopher[x . y]]␈↓

␈↓ ↓H␈↓The lemma then follows from this and the axioms ␈↓¬L10, ␈↓␈↓¬L11 ␈↓and ␈↓¬L15. ␈↓

␈↓ ↓H␈↓        ␈↓¬GOOD-FRINGE␈α␈↓folllows␈αfrom␈α ␈↓↓∀x:␈α[islist␈αfringe␈αx␈α∧␈α¬␈↓αn␈↓↓␈α∧fringe␈αx]␈↓␈α,␈α␈↓¬L3,␈α␈↓␈αand␈α␈↓¬L6.␈α␈↓␈αThe␈αformer␈αis
␈↓ ↓H␈↓proved using ␈↓¬SEXPINDUCTION. ␈↓

␈↓ ↓H␈↓        For␈α⊃␈↓¬FRINGE-ATM␈α⊃␈↓we␈α⊃assume␈α⊃␈↓↓␈↓αat␈↓↓␈αεx␈↓␈α⊃and␈α⊃show␈α⊃␈↓↓fringe x = fringe y ≡ x = y␈↓.␈α⊃ The␈α∩lemma␈α⊃then
␈↓ ↓H␈↓follows␈αfrom␈αthe␈αsymmetry␈αof␈αthe␈αoccurrences␈αof␈α␈↓↓x␈↓␈αand␈α␈↓↓y.␈↓␈α From␈αthe␈αdefinition␈αof␈α␈↓↓fringe␈↓␈αwe␈αhave
␈↓ ↓H␈↓␈↓↓fringe x = <x> = [x . ␈↓¬NIL␈↓↓]␈↓.␈α
 If␈α
␈↓↓␈↓αat␈↓↓ y␈↓␈α
the␈α
result␈α
follows␈α∞using␈α
␈↓¬EQ-SEXP.␈α
␈↓␈α
If␈α
␈↓↓¬␈↓αat␈↓↓ y␈↓␈α
then␈α
␈↓↓x ≠ y␈↓␈α∞and␈α
by
␈↓ ↓H␈↓␈↓¬EQ-SEXP␈α⊃␈↓we␈α⊃need␈α⊃only␈α⊂prove␈α⊃␈↓↓¬␈↓αn␈↓↓ ␈↓αd␈↓↓ fringe y␈↓.␈α⊃But␈α⊃this␈α⊂follows␈α⊃from␈α⊃␈↓¬CDR-APPEND␈α⊃␈↓and␈α⊂␈↓¬NOTNUL-
␈↓ ↓H␈↓¬APPEND. ␈↓

␈↓ ↓H␈↓        To prove ␈↓¬FRINGE-GOPHER ␈↓we use the "gopher trick" again and first prove

␈↓ ↓H␈↓␈↓ αS␈↓↓∀x y: [␈↓αa␈↓↓␈α∧fringe[x . y] = ␈↓αa␈↓↓␈α∧gopher[x . y] ∧ ␈↓αd␈↓↓␈α∧fringe[x . y] = fringe ␈↓αd␈↓↓␈α∧gopher[x . y]]␈↓ 

␈↓ ↓H␈↓using ␈↓¬SEPXINDUCTION. ␈↓ By ␈↓¬CAR-APPEND, ␈↓␈↓¬CDR-APPEND ␈↓and ␈↓¬FRINGE-CONS ␈↓we have

␈↓ ↓H␈↓␈↓ ∧U␈↓↓␈↓αa␈↓↓␈α∧fringe[x . y] = ␈↓αa␈↓↓␈α∧fringe x,              ␈↓ 
␈↓ ↓H␈↓60␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓and

␈↓ ↓H␈↓␈↓ ∧H␈↓↓␈↓αd␈↓↓␈α∧fringe[x . y] = [␈↓αd␈↓↓␈α∧fringe x] * fringe y. ␈↓ 

␈↓ ↓H␈↓In␈α
the␈α
case␈α
␈↓↓␈↓αat␈↓↓␈αεx␈↓␈α the␈α
result␈α
follows␈α
from␈α␈↓¬NIL-APPEND,␈α
␈↓␈↓¬GOPHER-CONS-ATM,␈α
␈↓␈α
 and␈α␈↓↓fringe x = [x . ␈↓¬NIL␈↓↓]␈↓␈α
.
␈↓ ↓H␈↓In the case ␈↓↓¬␈↓αat␈↓↓ x␈↓ we show

␈↓ ↓H␈↓␈↓ ∧Q␈↓↓fringe[x . y] = fringe[␈↓αa␈↓↓␈α∧x . [␈↓αd␈↓↓␈α∧x . y]]    ␈↓ 

␈↓ ↓H␈↓using␈α∪properties␈α∪of␈α∪␈↓↓append␈↓␈α∪and␈α∪␈↓¬FRINGE-CONS.␈α∩␈↓␈α∪Then␈α∪the␈α∪result␈α∪follows␈α∪from␈α∪the␈α∩induction
␈↓ ↓H␈↓hypothesis and ␈↓¬GOPHER-CONS-NOTATM. ␈↓ ␈↓¬FRINGE-GOPHER ␈↓now follows from the above using ␈↓¬L16. ␈↓

␈↓ ↓H␈↓        ␈↓¬ISTOT-SIZE␈α␈↓is␈α
proved␈αby␈αa␈α
straight␈αforward␈α
application␈αof␈α␈↓¬SEXPINDUCTION.␈α
␈↓␈αTo␈α
prove␈α␈↓¬SIZE-
␈↓ ↓H␈↓¬GOPHER ␈↓we first show

␈↓ ↓H␈↓␈↓ ∧R␈↓↓∀x y: [size ␈↓αd␈↓↓␈α∧gopher[x . y] < size[x . y]]␈↓ 

␈↓ ↓H␈↓using ␈↓¬SEXPINDUCTION. ␈↓ In the case ␈↓↓␈↓αa␈↓↓␈α∧x␈↓ we have

␈↓ ↓H␈↓␈↓ βa␈↓↓size ␈↓αd␈↓↓␈α∧gopher[x . y] = size y␈↓  and  ␈↓↓size[x . y] = 1 + size y␈↓ 

␈↓ ↓H␈↓by␈α␈↓¬SIZE,␈α␈↓␈↓¬SIZE-CONS␈α␈↓and␈α␈↓¬GOPHER-CONS-ATM␈α␈↓and␈αthe␈αresult␈αfollows␈αby␈α␈↓¬ORDER.␈αIn␈α␈↓the␈αcase␈α
␈↓↓¬␈↓αat␈↓↓ x␈↓␈αwe
␈↓ ↓H␈↓show

␈↓ ↓H␈↓␈↓ ¬¬␈↓↓size[x . y] = size[␈↓αa␈↓↓␈α∧x . [␈↓αd␈↓↓␈α∧x . y]]␈↓ 

␈↓ ↓H␈↓using␈α∪␈↓¬SIZE-CONS,␈α∩␈↓␈↓¬ASSOC␈α∪␈↓and␈α∩the␈α∪LISP␈α∩axioms.␈α∪The␈α∩result␈α∪then␈α∩follows␈α∪from␈α∪the␈α∩induction
␈↓ ↓H␈↓hypothesis and ␈↓¬GOPHER-CONS-NOTATM. ␈↓ ␈↓¬SIZE-GOPHER ␈↓now follows from ␈↓¬L16 ␈↓and ␈↓¬ORDER-PLUS. ␈↓

␈↓ ↓H␈↓        Now␈α∞we␈α
are␈α∞ready␈α
to␈α∞prove␈α∞the␈α
SAMEFRINGE␈α∞theorem.␈α
 The␈α∞proof␈α
is␈α∞divided␈α∞into␈α
two
␈↓ ↓H␈↓cases.  In the first case we assume ␈↓↓␈↓αat␈↓↓␈αεx ∨ ␈↓αat␈↓↓␈αεy␈↓.  Then by the ETV lemmas

␈↓ ↓H␈↓␈↓ ∧Q␈↓↓nnot aatom x aand nnot aatom y = ␈↓¬FF ␈↓↓␈↓, 

␈↓ ↓H␈↓by ␈↓¬FAANDP ␈↓and ␈↓¬ETVSAMEA ␈↓

␈↓ ↓H␈↓␈↓ ∧;␈↓↓␈↓¬FF ␈↓↓aand samea[gopher x, gopher y] = ␈↓¬FF ␈↓↓␈↓, 

␈↓ ↓H␈↓and by ␈↓¬POORF ␈↓

␈↓ ↓H␈↓␈↓ ¬⊗␈↓↓[x eeq y] aand ␈↓¬FF ␈↓↓= x eeq y ␈↓. 

␈↓ ↓H␈↓Thus by ␈↓¬SAMEFRINGEA ␈↓we have

␈↓ ↓H␈↓␈↓ ¬→␈↓↓samefringea[x, y] = x eeq y␈↓ 

␈↓ ↓H␈↓and ␈↓¬THM ␈↓now follows using the ETV lemmas, ␈↓¬FRINGE-ATM ␈↓and ␈↓¬SAMEFRINGE. ␈↓
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *61


␈↓ ↓H␈↓        In␈αthe␈αsecond␈α
case␈αwe␈αassume␈α␈↓↓¬␈↓αat␈↓↓␈αεx␈α
∧␈α¬␈↓αat␈↓↓␈αεy␈↓␈αand␈αmake␈α
use␈αof␈αthe␈α␈↓¬NUMBINDCTION␈α
␈↓axiom␈αand
␈↓ ↓H␈↓predicate as mentioned above.  In particular we have the induction hypothesis

␈↓ ↓H␈↓␈↓ β?␈↓↓∀m: [m < n ⊃ ∀x␈↓β1␈↓↓ y␈↓β1␈↓↓: [size x␈↓β1␈↓↓ + size y␈↓β1␈↓↓ = m ⊃ THM[x␈↓β1␈↓↓, y␈↓β1␈↓↓]] ␈↓. 

␈↓ ↓H␈↓Taking␈α∀ ␈↓↓n␈α∀=␈α∀size␈α∃x␈α∀+␈α∀size␈α∀y␈↓,␈α∃␈↓↓m␈α∀=␈α∀size␈α∀␈↓αd␈↓↓␈α∧gopher␈α∀x␈α∃+␈α∀size␈α∀␈↓αd␈↓↓␈α∧gopher␈α∀y␈↓,␈α∃␈↓↓x␈↓β1␈↓↓ = ␈↓αd␈↓↓ gopher x␈↓␈α∀and
␈↓ ↓H␈↓␈↓↓y␈↓β1␈↓↓ = ␈↓αd␈↓↓ gopher y␈↓ we have by ␈↓¬SIZE-GOPHER ␈↓

␈↓ ↓H␈↓␈↓¬THMCDRGO: ␈↓             ␈↓↓THM[␈↓αd␈↓↓␈α∧gopher x, ␈↓αd␈↓↓␈α∧gopher y]␈↓

␈↓ ↓H␈↓Assigning␈αthese␈αvalues␈αto␈α␈↓↓n␈↓␈αand␈α␈↓↓m␈↓␈αis␈αallowed␈αsince␈αby␈α␈↓¬ISTOT-PLUS,␈α␈↓␈α␈↓¬ISTOT-SIZE␈α␈↓and␈α␈↓¬GOOD-GOPHER
␈↓ ↓H␈↓¬␈↓the expressions satisfy ␈↓↓natnum.␈↓

␈↓ ↓H␈↓        ␈↓¬THM1␈α↔␈↓now␈α↔follows␈α↔from␈α↔␈↓¬THMCDRGO,␈α⊗␈↓the␈α↔ETV␈α↔lemmas,␈α↔␈↓¬GOOD-GOPHER,␈α↔␈↓␈↓¬SAMEA␈α↔␈↓␈α⊗and
␈↓ ↓H␈↓␈↓¬SAMEFRINGEA.␈α
␈↓␈α
␈↓¬THM2␈α
␈↓follows␈α
for␈αthe␈α
above␈α
reasons␈α
and␈α
␈↓¬SAME.␈α␈↓␈α
By␈α
␈↓¬SAMEA,␈α
␈↓␈α
␈↓¬SAMEFRINGE,␈α␈↓␈↓¬GOOD-
␈↓ ↓H␈↓¬GOPHER, ␈↓␈↓¬THMCDRGO ␈↓and the ETV lemmas it follows that

␈↓ ↓H␈↓␈↓ αj␈↓↓samea[gopher x, gopher y] = ␈↓¬TT ␈↓↓≡                                                    ␈↓
␈↓ ↓H␈↓␈↓ β'␈↓↓[␈↓αa␈↓↓␈α∧gopher x = ␈↓αa␈↓↓␈α∧gopher y] ∧ [fringe ␈↓αd␈↓↓␈α∧gopher x = fringe ␈↓αd␈↓↓␈α∧gopher y]␈↓.

␈↓ ↓H␈↓Using ␈↓¬FRINGE-GOPHER, ␈↓␈↓¬THM2, ␈↓and ␈↓¬SAME ␈↓we have

␈↓ ↓H␈↓␈↓ αW␈↓↓samefringe[x, y] ≡ x = y ∨ [[␈↓αa␈↓↓␈α∧fringe x = ␈↓αa␈↓↓␈α∧fringe y] ∧ [␈↓αd␈↓↓␈α∧fringe x = ␈↓αd␈↓↓␈α∧fringe y]]␈↓. 

␈↓ ↓H␈↓Finally ␈↓¬THM3 ␈↓follows from ␈↓¬EQ-SEXP ␈↓and ␈↓¬GOOD-FRINGE. ␈↓

␈↓ ↓H␈↓        Combining the two cases and applying the induction axiom we conclude

␈↓ ↓H␈↓␈↓ ∧&␈↓↓∀n: ∀x y: [[size x + size y] = n ⊃ THM[x, y]]␈↓ 

␈↓ ↓H␈↓and by ␈↓¬ISTOT-SIZE ␈↓and ␈↓¬ISTOT-PLUS ␈↓it follows that

␈↓ ↓H␈↓␈↓ ¬⊃␈↓↓∀x y: THM[x, y] .            ␈↓ 

␈↓ ↓H␈↓        In the above proof we could have equally well used the predicate

␈↓ ↓H␈↓␈↓ ∧T␈↓↓␈↓	F␈↓↓ n ≡ ∀x y: [size x = n ⊃ THM[x, y]]␈↓ 

␈↓ ↓H␈↓since the recursive call to ␈↓↓samefringe␈↓ always reduces the size of the first argument.

␈↓ ↓H␈↓        Another version of ␈↓↓samefringe␈↓ without any auxilliary functions is

␈↓ ↓H␈↓␈↓ αn␈↓↓samefringe[x, y] ← x = y ∨ [¬␈↓αat␈↓↓␈αεx ∧ ¬␈↓αat␈↓↓␈αεy ∧                                        ␈↓
␈↓ ↓H␈↓␈↓ βT␈↓↓[␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧x ␈↓αthen␈↓↓ [␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧y ␈↓αthen␈↓↓ ␈↓αa␈↓↓␈α∧x = ␈↓αa␈↓↓␈α∧y ∧ samefringe[␈↓αd␈↓↓␈α∧x, ␈↓αd␈↓↓␈α∧y] ␈↓
␈↓ ↓H␈↓␈↓ β8␈↓↓                                  ␈↓αelse␈↓↓ samefringe[x, ␈↓αaa␈↓↓␈α∧y. [␈↓αda␈↓↓␈α∧y . ␈↓αd␈↓↓␈α∧y]]]␈↓
␈↓ ↓H␈↓␈↓ β4␈↓↓             ␈↓αelse␈↓↓ samefringe[␈↓αaa␈↓↓␈α∧x . [␈↓αda␈↓↓␈α∧x . ␈↓αd␈↓↓␈α∧x], y].                    ␈↓

␈↓ ↓H␈↓Note that a recursive call to ␈↓↓samefringe␈↓ does one of the following:
␈↓ ↓H␈↓62␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓        1)  decreases  ␈↓↓size x + size y␈↓

␈↓ ↓H␈↓        2)  leaves  ␈↓↓size x + size y␈↓ and ␈↓↓size ␈↓αa␈↓↓␈α∧x␈↓ invariant and decreases ␈↓↓size ␈↓αa␈↓↓␈α∧y␈↓

␈↓ ↓H␈↓or

␈↓ ↓H␈↓        3)  leaves  ␈↓↓sixe x + size y␈↓ and ␈↓↓size ␈↓αa␈↓↓␈α∧y␈↓ invariant and decreases ␈↓↓size ␈↓αa␈↓↓␈α∧x ␈↓.

␈↓ ↓H␈↓This␈α∪can␈α∩lead␈α∪to␈α∪a␈α∩choice␈α∪of␈α∩an␈α∪induction␈α∪axiom␈α∩schema␈α∪in␈α∩at␈α∪least␈α∪two␈α∩ways.␈α∪ If␈α∪in␈α∩the
␈↓ ↓H␈↓␈↓¬NUMBINDUCTION␈α␈↓schema␈αwe␈αlet␈α␈↓↓n␈↓␈αand␈α␈↓↓m␈↓␈αrange␈αover␈αall␈αordinals␈αless␈αthan␈αa␈αgiven␈αone␈αit␈αbecomes␈αa
␈↓ ↓H␈↓schema␈α∩of␈α∩transfinite␈α∩induction.␈α⊃Ordinary␈α∩induction␈α∩is␈α∩obtained␈α⊃as␈α∩a␈α∩special␈α∩case␈α∩where␈α⊃the
␈↓ ↓H␈↓bounding␈α∞ordinal␈α∞is␈α∞␈↓	w␈↓␈α∞the␈α∞least␈α∞transfinite␈α∞ordinal.␈α∞ If␈α∞we␈α∞take␈α∞the␈α∞bounding␈α∞ordinal␈α∞to␈α∞be␈α
␈↓	w␈↓␈↓#
␈↓	␈↓#
w␈↓␈↓#
␈↓#
␈↓ ↓H␈↓then␈α
the␈α
SAMEFRINGE␈α
theorem␈α
for␈α
the␈α
above␈α
version␈α
of␈α
␈↓↓samefringe␈↓␈α
can␈α
be␈α
proved␈α
using␈α
the
␈↓ ↓H␈↓predicate

␈↓ ↓H␈↓␈↓ β⊃␈↓↓␈↓	F␈↓↓ n  ≡ ∀x y: [[size x +size y]␈↓	w␈↓↓ + size ␈↓αa␈↓↓␈α∧x + size ␈↓αa␈↓↓␈α∧y = n ⊃ THM[x, y]]␈↓ 

␈↓ ↓H␈↓(Note␈α∩that␈α∩THM2␈α⊃will␈α∩need␈α∩to␈α⊃be␈α∩modified␈α∩to␈α⊃account␈α∩for␈α∩the␈α⊃new␈α∩form␈α∩of␈α∩␈↓↓samefringe.)␈α⊃ ␈↓
␈↓ ↓H␈↓Alternately one could axiomatize the lexicographic ordering of triples of numbers by

␈↓ ↓H␈↓␈↓ β0␈↓↓∀l␈↓β1␈↓↓ m␈↓β1␈↓↓ n␈↓β1␈↓↓ l m n: [(l␈↓β1␈↓↓, m␈↓β1␈↓↓, n␈↓β1␈↓↓) < (l, m, n) ≡                         ␈↓
␈↓ ↓H␈↓␈↓ β]␈↓↓[l␈↓β1␈↓↓ < l] ∨ [l␈↓β1␈↓↓ = l ∧ m␈↓β1␈↓↓ < m] ∨ [l␈↓β1␈↓↓ = l ∧ m␈↓β1␈↓↓ = m ∧ n␈↓β1␈↓↓ < n]]␈↓

␈↓ ↓H␈↓This␈α∞ordering␈α∞is␈α
well-founded␈α∞(has␈α∞no␈α∞infinite␈α
decreasing␈α∞sequences)␈α∞and␈α
so␈α∞we␈α∞have␈α∞a␈α
schema
␈↓ ↓H␈↓analogous to ␈↓¬NUMBINDUCTION ␈↓given by

␈↓ ↓H␈↓␈↓ α]␈↓↓∀l m n: [∀l␈↓β1␈↓↓ m␈↓β1␈↓↓ n␈↓β1␈↓↓: [(l␈↓β1␈↓↓, m␈↓β1␈↓↓, n␈↓β1␈↓↓) < (l, m, n) ⊃␈↓	F␈↓↓(l␈↓β1␈↓↓, m␈↓β1␈↓↓, n␈↓β1␈↓↓)] ⊃ ␈↓	F␈↓↓(l, m, n)]␈↓
␈↓ ↓H␈↓␈↓ ¬A␈↓↓⊃ ∀l m n: ␈↓	F␈↓↓(l, m, n)␈↓

␈↓ ↓H␈↓The SAMEFRINGE theorem can now be proved using this schema with the predicate

␈↓ ↓H␈↓␈↓ αH␈↓↓␈↓	F␈↓↓(l, m, n) ≡ ∀x y: [l = size x +size y ∧ m = size ␈↓αa␈↓↓␈α∧y ∧ n = size ␈↓αa␈↓↓␈α∧x ⊃ THM[x, y]]␈↓ 



␈↓ ↓H␈↓11.  ␈↓αThe Minimization Schema.␈↓


␈↓ ↓H␈↓        As␈α∞mentioned␈α∞before,␈α∂the␈α∞functional␈α∞equation␈α∞of␈α∂a␈α∞program␈α∞doesn't␈α∞in␈α∂general␈α∞completely
␈↓ ↓H␈↓characterize it.  For example, the program

␈↓ ↓H␈↓␈↓ ¬'␈↓↓f1 x ← f1 x                  ␈↓ 

␈↓ ↓H␈↓leads to the sentence

␈↓ ↓H␈↓␈↓ ¬$␈↓↓∀x: [f1 x = f1 x]            ␈↓ 
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *63


␈↓ ↓H␈↓which␈α⊂provides␈α⊂no␈α⊂information␈α⊂although␈α∂the␈α⊂function␈α⊂␈↓↓f1␈↓␈α⊂is␈α⊂undefined␈α∂for␈α⊂all␈α⊂␈↓↓x.␈↓␈α⊂ This␈α⊂is␈α∂not
␈↓ ↓H␈↓always the case, since the program

␈↓ ↓H␈↓␈↓ ¬'␈↓↓f2 x ← [f2 x] . ␈↓¬NIL␈↓↓         ␈↓ 

␈↓ ↓H␈↓has the functional equation

␈↓ ↓H␈↓␈↓ ¬#␈↓↓∀x: [f2 x = [f2 x] . ␈↓¬NIL␈↓↓] . ␈↓ 

␈↓ ↓H␈↓from which ␈↓↓∀x: [¬issexp f2 x]␈↓ can be proved by induction.

␈↓ ↓H␈↓        In␈α⊃order␈α⊂to␈α⊃characterize␈α⊃recursive␈α⊂programs,␈α⊃we␈α⊃need␈α⊂some␈α⊃way␈α⊃of␈α⊂asking␈α⊃for␈α⊃the␈α⊂least
␈↓ ↓H␈↓defined␈αsolution␈αof␈αthe␈αfunctional␈αequation.␈α That␈αis␈αwe␈αwant␈αthe␈αleast␈αfixedpoint␈αof␈αthe␈αdefining
␈↓ ↓H␈↓functional.

␈↓ ↓H␈↓        Consider the recursive program

␈↓ ↓H␈↓␈↓ ¬-␈↓↓f x ← ␈↓	t␈↓↓[f] x                ␈↓ 

␈↓ ↓H␈↓which has the functional equation

␈↓ ↓H␈↓␈↓ ¬)␈↓↓∀x: [f x = ␈↓	t␈↓↓[f] x] .        ␈↓ 

␈↓ ↓H␈↓It␈αcan␈αbe␈α
shown␈αthat␈αrequiring␈α
a␈αfixedpoint␈α␈↓↓f␈↓␈α
of␈αa␈αfunctional␈α
␈↓	t␈↓␈αto␈αbe␈α
minimal␈αis␈αequivalent␈αto␈α
the
␈↓ ↓H␈↓␈↓↓minimization schema␈↓

␈↓ ↓H␈↓␈↓ ∧`␈↓↓∀x: [␈↓	t␈↓↓[F] x ␈↓πb␈↓↓ F x] ⊃ ∀x: [f x ␈↓πb␈↓↓ F x]␈↓ 

␈↓ ↓H␈↓where ␈↓↓F␈↓ is a function variable.

␈↓ ↓H␈↓        The␈α∞partial␈α∞ordering␈α∞can␈α∞be␈α∞removed␈α∂from␈α∞the␈α∞statement␈α∞of␈α∞the␈α∞minimization␈α∂schema␈α∞by
␈↓ ↓H␈↓noting that for functions ␈↓↓f␈↓ and ␈↓↓g␈↓ we have

␈↓ ↓H␈↓␈↓ ∧{␈↓↓f ␈↓πb␈↓↓ g ≡ ∀x: [isD f x ⊃ f x = g x]␈↓ 

␈↓ ↓H␈↓where␈αD␈αis␈αthe␈αdomain␈αcontaining␈αthe␈αrange␈αof␈α␈↓↓f␈↓␈αand␈αthe␈αpredicate␈α␈↓↓isD␈↓␈αstates␈αthat␈αits␈αargument␈αis
␈↓ ↓H␈↓in the domain D. Thus ␈↓↓isD f x␈↓ means that ␈↓↓f x ≠ ␈↓πT␈↓↓␈↓.  The minimization schema then becomes

␈↓ ↓H␈↓␈↓ βB␈↓↓∀x: [isD ␈↓	t␈↓↓[F] x ⊃ F x = ␈↓	t␈↓↓[F] x] ⊃ ∀x: [isD f x ⊃ f x = F x] ␈↓. 

␈↓ ↓H␈↓        The␈α∂simplest␈α∞application␈α∂of␈α∂the␈α∞schema␈α∂is␈α∞to␈α∂show␈α∂that␈α∞the␈α∂program␈α∞for␈α∂␈↓↓f1␈↓␈α∂given␈α∞above
␈↓ ↓H␈↓computes the totally undefined function.  The schema becomes

␈↓ ↓H␈↓␈↓ ∧d␈↓↓∀x: [F x ␈↓πb␈↓↓ F x] ⊃ ∀x: [f1 x ␈↓πb␈↓↓ F x] ␈↓. 

␈↓ ↓H␈↓The␈α⊂left␈α⊂side␈α∂of␈α⊂the␈α⊂implication␈α⊂is␈α∂identically␈α⊂true.␈α⊂ Taking␈α⊂F[x]␈α∂=␈α⊂␈↓πT␈↓,␈α⊂ and␈α⊂remembering␈α∂that
␈↓ ↓H␈↓␈↓↓X ␈↓πb␈↓↓ ␈↓πT␈↓↓␈↓ only if ␈↓↓X = ␈↓πT␈↓↓␈↓, the right side tells us that ␈↓↓f1 x = ␈↓πT␈↓↓␈↓.
␈↓ ↓H␈↓64␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓        The␈α⊃minimization␈α⊃schema␈α∩provides␈α⊃an␈α⊃alternate␈α⊃method␈α∩for␈α⊃proving␈α⊃the␈α∩correctness␈α⊃of
␈↓ ↓H␈↓␈↓↓samefringe.␈↓␈α
 To␈α
simplify␈α
matters␈α
we␈α
eliminate␈αthe␈α
auxilliary␈α
function␈α
␈↓↓samea␈↓␈α
from␈α
the␈αdefinition␈α
of
␈↓ ↓H␈↓␈↓↓samefringea␈↓␈α∂thus␈α∞eliminating␈α∂the␈α∞problem␈α∂of␈α∞having␈α∂to␈α∞deal␈α∂with␈α∞mutually␈α∂recursive␈α∞programs.
␈↓ ↓H␈↓The functional defining ␈↓↓samefringea␈↓ now becomes

␈↓ ↓H␈↓␈↓ α≠␈↓↓␈↓	t␈↓↓ = λF: λx y: [[x eeq y] oor [[nnot aatom x aand nnot aatom y] aand                         ␈↓
␈↓ ↓H␈↓␈↓ α⎇␈↓↓             [[␈↓αa␈↓↓␈α∧gopher x eeq ␈↓αa␈↓↓␈α∧gopher y] aand F[␈↓αd␈↓↓␈α∧gopher x, ␈↓αd␈↓↓␈α∧gopher y]]]] ␈↓.

␈↓ ↓H␈↓Now␈αwe␈α
form␈αan␈α
axiom␈αschema␈α
from␈αthe␈αminimization␈α
schema␈αby␈α
using␈αthe␈α
␈↓	t␈↓␈αgiven␈α
above␈αand
␈↓ ↓H␈↓␈↓↓samefringea␈↓ for ␈↓↓f.␈↓ We instantiate this schema with

␈↓ ↓H␈↓␈↓ ∧;␈↓↓F[x, y] = fringe x eeq fringe y  .           ␈↓ 

␈↓ ↓H␈↓The proof then consists of the following steps

␈↓ ↓H␈↓        1)      ␈↓↓∀x y: [istv ␈↓	t␈↓↓[F] [x, y]]␈↓

␈↓ ↓H␈↓        2)      ␈↓↓∀x y: [F[x, y] = ␈↓	t␈↓↓[F] [x, y]]␈↓

␈↓ ↓H␈↓        3)      ␈↓↓∀x y: istv samefringea[x, y]␈↓

␈↓ ↓H␈↓from 1) - 3) and the axiom instantiation we conclude

␈↓ ↓H␈↓        4)      ␈↓↓∀x y: [fringe x eeq fringe y = samefringea[x, y]]␈↓

␈↓ ↓H␈↓from␈α3)␈αwe␈αknow␈αthat␈α␈↓↓samefringea[x, y]␈↓␈αis␈αeither␈α␈↓¬TT␈α␈↓or␈α␈↓¬FF␈α␈↓and␈αso␈αby␈αa␈αsimple␈αcase␈αanalysis␈αusing
␈↓ ↓H␈↓the TV-lemmas, the fact that ␈↓¬TT ␈↓≠ ␈↓¬FF, the ␈↓definition of ␈↓↓samefringe␈↓ and 4) we conclude

␈↓ ↓H␈↓        5)      ␈↓↓∀x y: [samefringe[x, y] ≡ fringe x = fringe y]␈↓

␈↓ ↓H␈↓as desired.

␈↓ ↓H␈↓        The␈αminimization␈αschema␈αcan␈αsometimes␈αbe␈αused␈αto␈αshow␈αpartial␈αcorrectness.␈α For␈αexample,
␈↓ ↓H␈↓the well known 91-function is defined by the recursive program over the integers

␈↓ ↓H␈↓␈↓ βq␈↓↓f91 x ← ␈↓αif␈↓↓ x > 100 ␈↓αthen␈↓↓ x - 10 ␈↓αelse␈↓↓ f91 f91 [x + 11] ␈↓. 

␈↓ ↓H␈↓The goal is to show that

␈↓ ↓H␈↓␈↓ ∧⊃␈↓↓∀x: [f91 x = ␈↓αif␈↓↓ x > 100 ␈↓αthen␈↓↓ x - 10 ␈↓αelse␈↓↓ 91] .    ␈↓ 

␈↓ ↓H␈↓We apply the minimization schema with

␈↓ ↓H␈↓␈↓ ∧∩␈↓↓F x = ␈↓αif␈↓↓ x > 100 ␈↓αthen␈↓↓ x - 10 ␈↓αelse␈↓↓ 91 ,            ␈↓ 

␈↓ ↓H␈↓and␈α
it␈αcan␈α
be␈α
shown␈αby␈α
an␈α
explicit␈αcalculation␈α
without␈α
induction␈αthat␈α
the␈α
premiss␈αof␈α
the␈αschema␈α
is
␈↓ ↓H␈↓satisfied, and this shows that ␈↓↓f91,␈↓ whenever defined has the desired value.
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *65


␈↓ ↓H␈↓        The␈α∂method␈α∂of␈α∂␈↓↓recursion␈↓␈α∂␈↓↓induction␈↓␈α∂is␈α∂also␈α∂an␈α∂immediate␈α∂application␈α∂of␈α∂the␈α∞minimization
␈↓ ↓H␈↓schema.␈α
 If␈αwe␈α
show␈αthat␈α
two␈αfunctions␈α
satisfy␈αthe␈α
schema␈αof␈α
a␈αrecursive␈α
program,␈αwe␈α
show␈αthat
␈↓ ↓H␈↓they both equal the function computed by the program whereever the function is defined.

␈↓ ↓H␈↓        The␈α
utility␈α
of␈α
the␈α
minimization␈αschema␈α
for␈α
proving␈α
partial␈α
correctness␈α
or␈αnon-termination
␈↓ ↓H␈↓depends␈α∂on␈α∞our␈α∂ability␈α∞to␈α∂name␈α∂suitable␈α∞comparison␈α∂functions.␈α∞ ␈↓↓f1␈↓␈α∂and␈α∞␈↓↓f91␈↓␈α∂were␈α∂easily␈α∞treated,
␈↓ ↓H␈↓because␈α⊃the␈α⊃necessary␈α⊃comparison␈α⊃functions␈α⊃could␈α⊃be␈α⊃given␈α⊃explicitly␈α⊃without␈α⊃recursion.␈α⊂ Any
␈↓ ↓H␈↓extension␈αof␈αthe␈αlanguage␈αthat␈αprovides␈αnew␈αtools␈αfor␈αnaming␈αcomparison␈αfunctions,␈αe.g.␈αgoing␈αto
␈↓ ↓H␈↓higher order logic, will improve our ability to use the schema in proofs.

␈↓ ↓H␈↓        The␈α
minimization␈α
schema␈α
can␈α
be␈α
regarded␈α∞as␈α
an␈α
axiom␈α
schema␈α
involving␈α
a␈α∞second␈α
order
␈↓ ↓H␈↓function␈α
variable␈α
␈↓	t␈↓.␈α
 What␈α
can␈α
be␈α
substituted␈α∞for␈α
␈↓	t␈↓␈α
is␈α
a␈α
 quantifier␈α
free␈α
λ-expression␈α
in␈α∞a␈α
first
␈↓ ↓H␈↓order␈αfunction␈α
variable.␈α It␈αmay␈α
be␈αinteresting␈αto␈α
study␈αthe␈αsets␈α
of␈αfirst␈αorder␈α
sentences␈αthat␈αcan␈α
be
␈↓ ↓H␈↓generated␈α
by␈α
such␈αsecond␈α
order␈α
sentence␈αschemata.␈α
 Presumably,␈α
sets␈αof␈α
sentences␈α
can␈αbe␈α
generated
␈↓ ↓H␈↓in this way that cannnot be generated by schemata with only first order function variables.

␈↓ ↓H␈↓α␈↓ εεExercises.


␈↓ ↓H␈↓α1. Simple structural induction proofs.

␈↓ ↓H␈↓Prove the following statements.

␈↓ ↓H␈↓        i)      ␈↓↓∀u: u * ␈↓¬NIL␈↓↓ = u␈↓

␈↓ ↓H␈↓        ii)     ␈↓↓∀u: islist reverse1 u␈↓

␈↓ ↓H␈↓        iii)    ␈↓↓∀u: reverse u = reverse1 u␈↓

␈↓ ↓H␈↓        iv)     ␈↓↓∀u: reverse reverse u = u␈↓

␈↓ ↓H␈↓        v)      ␈↓↓∀u v: reverse[u * v] = [reverse v] * [reverse u]␈↓

␈↓ ↓H␈↓        vi)     ␈↓↓∀x: flatten x = fringe x␈↓

␈↓ ↓H␈↓        vii)    ␈↓↓∀x: (¬␈↓αat␈↓↓␈αεx ⊃ size gopher x = size x)␈↓

␈↓ ↓H␈↓        viii)   ␈↓↓∀x: (¬␈↓αat␈↓↓␈αεx ⊃ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧gopher x)␈↓

␈↓ ↓H␈↓where the necessary LISP function definitions are:

␈↓ ↓H␈↓                ␈↓↓u * v ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ v ␈↓αelse␈↓↓ ␈↓αa␈↓↓␈α∧u . [␈↓αd␈↓↓␈α∧u * v]␈↓

␈↓ ↓H␈↓                ␈↓↓reverse1 u ← if ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ [reverse1 ␈↓αd␈↓↓␈α∧u] * <␈↓αa␈↓↓␈α∧u>␈↓

␈↓ ↓H␈↓                ␈↓↓reverse u ← rev[u, ␈↓¬NIL␈↓↓]␈↓

␈↓ ↓H␈↓                ␈↓↓rev[u, v] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ v ␈↓αelse␈↓↓ rev[␈↓αd␈↓↓␈α∧u, ␈↓αa␈↓↓␈α∧u . v]␈↓
␈↓ ↓H␈↓66␈↓ ¬dCHAPTER III␈↓ H


␈↓ ↓H␈↓                ␈↓↓flatten x ← flat[x, ␈↓¬NIL␈↓↓]␈↓

␈↓ ↓H␈↓                ␈↓↓flat[x, u] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ [x . u] ␈↓αelse␈↓↓ flat[␈↓αa␈↓↓␈α∧x, flat[␈↓αd␈↓↓␈α∧x, u]]␈↓

␈↓ ↓H␈↓                ␈↓↓fringe x ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ <x> ␈↓αelse␈↓↓ [fringe ␈↓αa␈↓↓␈α∧x] * [fringe ␈↓αd␈↓↓␈α∧x]␈↓

␈↓ ↓H␈↓                ␈↓↓gopher x ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧x ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ gopher[␈↓αaa␈↓↓␈α∧x . [␈↓αda␈↓↓␈α∧x . ␈↓αd␈↓↓␈α∧x]]␈↓

␈↓ ↓H␈↓                ␈↓↓size x ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ 1 ␈↓αelse␈↓↓ size ␈↓αa␈↓↓␈α∧x + size ␈↓αd␈↓↓␈α∧x␈↓


␈↓ ↓H␈↓α2. Properties of substitutions and substitution lists.

␈↓ ↓H␈↓        With␈α∩function␈α∪definitions␈α∩as␈α∩given␈α∪below,␈α∩␈↓↓subst[x, y, z]␈↓␈α∩is␈α∪the␈α∩result␈α∩of␈α∪replacing␈α∩the
␈↓ ↓H␈↓variable␈α
␈↓↓y␈↓␈α
by␈α
the␈α
S-expression␈α
␈↓↓x␈↓␈α
whereever␈α
␈↓↓y␈↓␈α
occurs␈αin␈α
␈↓↓z.␈↓␈α
 If␈α
␈↓↓s␈↓␈α
is␈α
a␈α
list␈α
of␈α
substitutions␈α
of␈αthe␈α
form
␈↓ ↓H␈↓␈↓↓<y . x>␈↓␈α
then␈α␈↓↓sublis[z, s]␈↓␈α
is␈αthe␈α
result␈αof␈α
"simultaneously"␈α
performing␈αall␈α
of␈αthe␈α
substitutions␈αon␈α
the
␈↓ ↓H␈↓list␈α
to␈α␈↓↓z.␈↓␈α
If␈α
␈↓↓s1␈↓␈αand␈α
␈↓↓s2␈↓␈α
are␈αlists␈α
of␈α
substitutions␈αthen␈α
␈↓↓s1␈↓␈α
@␈α␈↓↓s1␈↓␈α
is␈α
"composition"␈α of␈α
the␈α
two.␈α Prove␈α
the
␈↓ ↓H␈↓following properties.

␈↓ ↓H␈↓        i)      ␈↓↓∀x y z: subst[x, y, z] = sublis[z, <y . x>]␈↓

␈↓ ↓H␈↓        ii)     ␈↓↓∀z s1 s2: sublis[z, s1 @ s2] = sublis[sublis[z, s1], s2]␈↓

␈↓ ↓H␈↓        iii)    ␈↓↓∀z s1 s2 s3: sublis[z, s1 @ [s2 @ s3]] = sublis[z, [s1 @ s2] @ s3]␈↓

␈↓ ↓H␈↓        iv)     ␈↓↓∀x y z: (¬occur[y, z] ⊃ subst[x, y, z] = z)␈↓

␈↓ ↓H␈↓        v)      ␈↓↓∀x x1 y y1 z: ((x ≠  x1 ∧ ¬occur[y, x1]) ⊃ ␈↓
␈↓ ↓H␈↓                        ␈↓↓subst[x1, y1, subst[x, y, z]] = subst[subst[x1, y1, x], y, subst[x1, y1, z]])␈↓


␈↓ ↓H␈↓where

␈↓ ↓H␈↓        ␈↓↓assoc[x, s] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧s ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ ␈↓αif␈↓↓ x = ␈↓αaa␈↓↓␈α∧s ␈↓αthen␈↓↓ ␈↓αa␈↓↓␈α∧s ␈↓αelse␈↓↓ assoc[x, ␈↓αd␈↓↓␈α∧s]␈↓

␈↓ ↓H␈↓        ␈↓↓subst[x, y, z] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεz ␈↓αthen␈↓↓ [␈↓αif␈↓↓ y = z ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ z] ␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ subst[x, y, ␈↓αa␈↓↓␈α∧z] . subst[x, y, ␈↓αd␈↓↓␈α∧z]␈↓

␈↓ ↓H␈↓        ␈↓↓occur[x, y] ← [x = y] ∨ [¬␈↓αat␈↓↓␈αεy ∧ [occur[x, ␈↓αa␈↓↓␈α∧y] ∨ occur[x, ␈↓αd␈↓↓␈α∧y]]]␈↓.

␈↓ ↓H␈↓        ␈↓↓sublis[x, s] ← ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ {assoc[x, s]}[λz: ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧z ␈↓αthen␈↓↓ x ␈↓αelse␈↓↓ ␈↓αd␈↓↓␈α∧z]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ sublis[␈↓αa␈↓↓␈α∧x, s] . sublis[␈↓αd␈↓↓␈α∧x, s]␈↓

␈↓ ↓H␈↓        ␈↓↓s1 @ s2 ← subsub[s1, s2] * s2␈↓

␈↓ ↓H␈↓        ␈↓↓subsub[s1, s2] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧s1 ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ [␈↓αaa␈↓↓␈α∧s1 . sublis[␈↓αda␈↓↓␈α∧s1, s2]] . subsub[␈↓αd␈↓↓␈α∧s1, s2]␈↓
␈↓ ↓H␈↓␈↓ ¬dCHAPTER III␈↓ *67


␈↓ ↓H␈↓α3. Pattern matching and unification properties.

␈↓ ↓H␈↓        (This is a fairly substantial exercise.)

␈↓ ↓H␈↓        With␈α∂the␈α∞addition␈α∂function␈α∞definitions␈α∂given␈α∂below,␈α∞␈↓↓inst[x, y, ␈↓¬NIL␈↓↓]␈↓␈α∂is␈α∞␈↓¬NO␈α∂␈↓if␈α∞␈↓↓x␈↓␈α∂is␈α∂not␈α∞and
␈↓ ↓H␈↓instance␈αof␈αthe␈αpattern␈α␈↓↓y,␈↓␈αand␈αotherwise␈αis␈αthe␈αlist␈αof␈αsubstitions␈αwhich␈αwill␈αconvert␈α␈↓↓y␈↓␈αinto␈α␈↓↓x.␈↓␈α In
␈↓ ↓H␈↓the latter case we have ␈↓↓x = sublis[y, inst[x, y, ␈↓¬NIL␈↓↓]␈↓.  Prove

␈↓ ↓H␈↓        i)      ␈↓↓∀x y s: (inst[x, y, s] ≠ ␈↓¬NO ␈↓↓⊃ x = sublis[y, inst[x, y, s]])␈↓

␈↓ ↓H␈↓        ␈↓↓unify[x,y]␈↓␈αattempts␈αto␈αfind␈αthe␈αmost␈αgeneral␈αpattern␈αwhich␈αis␈αan␈αinstance␈αof␈αboth␈α␈↓↓x␈↓␈αand␈α␈↓↓y.␈↓
␈↓ ↓H␈↓If␈α
no␈α
such␈α
pattern␈α
exists␈α∞the␈α
it␈α
returns␈α
␈↓¬NO,␈α
␈↓otherwise␈α
it␈α∞returns␈α
a␈α
list␈α
of␈α
substitutions␈α∞which␈α
will
␈↓ ↓H␈↓convert both ␈↓↓x␈↓ and ␈↓↓y␈↓ into that pattern.  Prove

␈↓ ↓H␈↓        ii)     ␈↓↓∀x y: (unify[x, y] ≠ ␈↓¬NO ␈↓↓⊃ sublis[x, unify[x, y]] = sublis[y, unify[x, y]])␈↓

␈↓ ↓H␈↓        iii)    ␈↓↓∀x y: (unify[x, y] = ␈↓¬NO ␈↓↓⊃ ∀s: sublis[x, s] ≠ sublis[y, s])␈↓

␈↓ ↓H␈↓        iv)     ␈↓↓∀x y s: (sublis[x, s] = sublis[y, s] ⊃ ∃s1: ∀z: sublis[z, s] = sublis[z, unify[x, y] @ s1])␈↓

␈↓ ↓H␈↓where

␈↓ ↓H␈↓        ␈↓↓inst[x, y, s] ← ␈↓αif␈↓↓ s = ␈↓¬NO ␈↓↓␈↓αthen␈↓↓ ␈↓¬NO ␈↓↓␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεy ␈↓αthen␈↓↓ [␈↓αif␈↓↓ isvar y ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓                                ␈↓↓{assoc[y, s]}[λz: ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧z ␈↓αthen␈↓↓ [y . x] . s ␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αd␈↓↓␈α∧z = x ␈↓αthen␈↓↓ s ␈↓αelse␈↓↓ ␈↓¬NO ␈↓↓]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ y = x ␈↓αthen␈↓↓ s ␈↓αelse␈↓↓ ␈↓¬NO ␈↓↓]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεx ␈↓αthen␈↓↓ ␈↓¬NO ␈↓↓␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ inst[␈↓αd␈↓↓␈α∧x, ␈↓αd␈↓↓␈α∧y, inst[␈↓αa␈↓↓␈α∧x, ␈↓αa␈↓↓␈α∧y, s]]␈↓

␈↓ ↓H␈↓        ␈↓↓isvar x ← x = ␈↓¬U ␈↓↓∨ x = ␈↓¬V ␈↓↓∨ x = ␈↓¬W ␈↓↓∨ x = ␈↓¬X ␈↓↓∨ x = ␈↓¬Y ␈↓↓∨ x = ␈↓¬Z ␈↓↓␈↓

␈↓ ↓H␈↓        ␈↓↓unify[x, y] ← ␈↓αif␈↓↓ x = y ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ isvar x ␈↓αthen␈↓↓ [␈↓αif␈↓↓ occur[x, y] ␈↓αthen␈↓↓ ␈↓¬NO ␈↓↓␈↓αelse␈↓↓ <x . y>]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ isvar y ␈↓αthen␈↓↓ [␈↓αif␈↓↓ occur[y, x] ␈↓αthen␈↓↓ ␈↓¬NO ␈↓↓␈↓αelse␈↓↓ <y . x>]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ [␈↓αat␈↓↓␈αεx ∨ ␈↓αat␈↓↓␈αεy] ␈↓αthen␈↓↓ ␈↓¬NO ␈↓↓␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ {unify[␈↓αa␈↓↓␈α∧x,␈↓αa␈↓↓␈α∧y]}␈↓
␈↓ ↓H␈↓                        ␈↓↓[λs1: ␈↓αif␈↓↓ s1 = ␈↓¬NO ␈↓↓␈↓αthen␈↓↓ ␈↓¬NO ␈↓↓␈↓
␈↓ ↓H␈↓                            ␈↓↓␈↓αelse␈↓↓ {unify[sublis[␈↓αd␈↓↓␈α∧x, s1],sublis[␈↓αd␈↓↓␈α∧y, s1]]}␈↓
␈↓ ↓H␈↓                                ␈↓↓[λs2: ␈↓αif␈↓↓ s2 = ␈↓¬NO ␈↓↓␈↓αthen␈↓↓ ␈↓¬NO ␈↓↓␈↓αelse␈↓↓ s1 @ s2]]␈↓
␈↓ ↓H␈↓68␈↓ εH␈↓ H


␈↓ ↓H␈↓α␈↓ ¬{Chapter IV

␈↓ ↓H␈↓α␈↓ ∧
INTERPRETING AND COMPILING IN LISP


␈↓ ↓H␈↓        Interpreting␈α∀and␈α∀compiling␈α∀are␈α∀important␈α∀examples␈α∀of␈α∀symbolic␈α∀computation.␈α∀ In␈α∀this
␈↓ ↓H␈↓chapter␈α
we␈α
describe␈α
the␈α
LISP␈α
function␈α
␈↓↓eval␈↓␈α
which␈α
forms␈α
the␈α
basis␈α
for␈α
the␈α
LISP␈α∞interpreter␈α
and
␈↓ ↓H␈↓two LISP compilers, LCOM0 and LCOM4.



␈↓ ↓H␈↓1.  ␈↓αThe function ␈↓↓eval.␈↓α ␈↓


␈↓ ↓H␈↓        ␈↓↓eval␈↓␈αplays␈αboth␈αa␈αtheoretical␈αand␈αa␈αpractical␈αrole␈αin␈αLISP.␈α Historically,␈αthe␈αlist␈αnotation␈αfor
␈↓ ↓H␈↓LISP␈αfunctions␈αand␈α␈↓↓eval␈↓␈α
were␈αfirst␈αdevised␈αin␈α
order␈αto␈αshow␈αhow␈αeasy␈α
it␈αis␈αto␈αdefine␈α
a␈αuniversal
␈↓ ↓H␈↓function␈α
in␈αLISP␈α
-␈αthe␈α
idea␈α
was␈αto␈α
advocate␈αLISP␈α
as␈α
an␈αalternative␈α
to␈αTuring␈α
machines␈αfor␈α
doing
␈↓ ↓H␈↓the␈α∂elementary␈α⊂theory␈α∂of␈α∂computability.␈α⊂ This␈α∂role␈α∂will␈α⊂be␈α∂discussed␈α∂in␈α⊂a␈α∂later␈α∂chapter.␈α⊂  S.␈α∂R.
␈↓ ↓H␈↓Russell␈α∞noted␈α∞that␈α∞␈↓↓eval␈↓␈α∞could␈α∞serve␈α∞as␈α∞an␈α∞interpreter␈α∞for␈α∞LISP␈α∞and␈α∞promptly␈α∞programmed␈α∞it␈α∞in
␈↓ ↓H␈↓machine␈αlanguage␈αwith␈αminor␈αmodifications␈αto␈αmake␈αit␈αmore␈αpractical.␈α Since␈αa␈αcompiler␈αwas␈αlong
␈↓ ↓H␈↓delayed,␈α∃interpreters␈α∃are␈α∃more␈α∃easily␈α∃modified␈α∃and␈α∃handle␈α∃functional␈α∃arguments␈α∃better,␈α∀an
␈↓ ↓H␈↓interpreter based on ␈↓↓eval␈↓ has remained a feature of most LISP systems.

␈↓ ↓H␈↓        ␈↓↓eval␈↓␈αhas␈α
two␈αarguments␈α
the␈αfirst␈α
of␈αwhich␈α
is␈αa␈α
LISP␈αexpression␈α
in␈αinternal␈α
notation,␈αwhile
␈↓ ↓H␈↓the␈α∂second␈α∂is␈α⊂a␈α∂list␈α∂of␈α⊂pairs␈α∂that␈α∂give␈α⊂the␈α∂values␈α∂of␈α⊂any␈α∂free␈α∂variables␈α⊂that␈α∂may␈α∂occur␈α⊂in␈α∂the
␈↓ ↓H␈↓expression.␈α⊃ The␈α⊂result␈α⊃is␈α⊂the␈α⊃value␈α⊂of␈α⊃the␈α⊂first␈α⊃argument␈α⊂in␈α⊃an␈α⊂environment␈α⊃where␈α⊃the␈α⊂free
␈↓ ↓H␈↓variables␈α
are␈α
assigned␈α
the␈α
values␈α
given␈α
by␈α
the␈α
second␈α
argument.␈α
 Since␈α
any␈α
computation␈α
can␈α
be
␈↓ ↓H␈↓described␈α∞as␈α∞evaluating␈α∂an␈α∞expression␈α∞without␈α∂free␈α∞variables,␈α∞the␈α∂second␈α∞argument␈α∞plays␈α∂a␈α∞role
␈↓ ↓H␈↓mainly␈αin␈αthe␈αrecursive␈αdefinition␈αof␈α␈↓↓eval,␈↓␈αand␈αwe␈αusually␈αstart␈αour␈αcomputations␈αwith␈αthe␈αsecond
␈↓ ↓H␈↓argument ␈↓¬NIL␈↓.

␈↓ ↓H␈↓        To␈αillustrate␈α
this,␈αsuppose␈α
we␈αwant␈αto␈α
apply␈αthe␈α
function␈α␈↓↓alt␈↓␈αto␈α
the␈αlist␈α
␈↓¬(A␈αB␈αC␈α
D␈αE)␈↓,␈α
i.e.␈αwe
␈↓ ↓H␈↓wish to evaluate ␈↓↓alt[␈↓¬(A B C D E)␈↓↓]␈↓.  This can be obtained by computing

␈↓ ↓H␈↓                      ␈↓↓eval[␈↓␈↓¬((LABEL ALT␈↓
␈↓ ↓H␈↓                                  ␈↓¬(LAMBDA (X) (COND ((OR (NULL X) (NULL (CDR X))) X)␈↓
␈↓ ↓H␈↓                                                    ␈↓¬(T (CONS (CAR X) (ALT (CDDR X)))))))␈↓
␈↓ ↓H␈↓                                 ␈↓¬(QUOTE (A B C D E)))␈↓
␈↓ ↓H␈↓                              ,␈↓↓␈↓¬NIL␈↓↓]␈↓,

␈↓ ↓H␈↓which␈αgives␈αthe␈αexpected␈αresult␈α␈↓¬(A␈αC␈αE)␈↓.␈α The␈αsecond␈αargument␈αof␈α␈↓↓eval,␈↓␈αtaken␈αas␈α␈↓¬NIL␈↓␈αin␈αthe␈αabove
␈↓ ↓H␈↓example,␈α
is␈α
a␈α
list␈α
of␈α
dotted␈α
pairs␈α
where␈α
the␈α
first␈α
element␈α
of␈α
each␈α
pair␈α
is␈α
an␈α
atom␈α
representing␈α
a
␈↓ ↓H␈↓variable␈α∞and␈α∂the␈α∞second␈α∂element␈α∞is␈α∂the␈α∞value␈α∂assigned␈α∞to␈α∂that␈α∞variable.␈α∂ A␈α∞variable␈α∂may␈α∞occur
␈↓ ↓H␈↓more␈α∞than␈α∞once␈α∞in␈α
the␈α∞list␈α∞and␈α∞the␈α∞value␈α
chosen␈α∞is␈α∞that␈α∞paired␈α
with␈α∞the␈α∞first␈α∞occurrence␈α∞of␈α
the
␈↓ ↓H␈↓variable.  We illustrate this by the equation

␈↓ ↓H␈↓␈↓ ∧M␈↓↓eval[␈↓¬(CAR X), ((X.(B.C)) (Y.A) (X.B))␈↓↓] = ␈↓¬B, ␈↓↓␈↓ 
␈↓ ↓H␈↓␈↓ ¬cCHAPTER IV␈↓ *69


␈↓ ↓H␈↓i.e.␈αwe␈αhave␈αevaluated␈α␈↓αa␈↓␈α∧␈↓↓x␈↓␈αwith␈α␈↓↓x␈↓␈α=␈α␈↓¬(B.C).␈α
␈↓␈α The␈αvalue␈αassociated␈αwith␈αa␈αvariable␈αin␈αsuch␈αa␈α
list␈αof
␈↓ ↓H␈↓pairs is computed by the auxiliary function ␈↓↓assoc␈↓ which has the recursive definition

␈↓ ↓H␈↓␈↓ β_␈↓↓assoc[v, a] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧a ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧a = v ␈↓αthen␈↓↓ ␈↓αa␈↓↓␈α∧a ␈↓αelse␈↓↓ alt[v, ␈↓αd␈↓↓␈α∧a]␈↓. 

␈↓ ↓H␈↓Thus we have

␈↓ ↓H␈↓␈↓ ∧K␈↓↓assoc[␈↓¬X, ␈↓↓␈↓¬((X.(B.C)) (Y.A) (X.B))␈↓↓] = ␈↓¬(X.(B.C))␈↓↓␈↓. 

␈↓ ↓H␈↓(The␈α
value␈α
of␈α
␈↓↓assoc␈↓␈αis␈α
taken␈α
as␈α
the␈α
successful␈αpair␈α
rather␈α
than␈α
as␈α
its␈αsecond␈α
element␈α
so␈α
that␈α␈↓¬NIL␈↓␈α
can
␈↓ ↓H␈↓be given as an answer when when the search is unsuccessful).

␈↓ ↓H␈↓        A simplified version of the usual LISP ␈↓↓eval␈↓ is the following:

␈↓ ↓H␈↓        ␈↓↓eval[e, a] ←␈↓
␈↓ ↓H␈↓        ␈↓↓␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεe ␈↓αthen␈↓↓ [␈↓αif␈↓↓ numberp e ∨ e  = ␈↓¬NIL␈↓↓ ∨ e = ␈↓¬T␈↓↓ ␈↓αthen␈↓↓ e  ␈↓αelse␈↓↓ ␈↓αd␈↓↓␈α∧assoc[e, a]]␈↓
␈↓ ↓H␈↓        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧e ␈↓αthen␈↓↓␈↓
␈↓ ↓H␈↓                ␈↓↓[␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬CAR ␈↓↓␈↓αthen␈↓↓ ␈↓αa␈↓↓␈α∧eval[␈↓αad␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬CDR ␈↓↓␈↓αthen␈↓↓ ␈↓αd␈↓↓␈α∧eval[␈↓αad␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬CONS ␈↓↓␈↓αthen␈↓↓ eval[␈↓αad␈↓↓␈α∧e, a] . eval[␈↓αadd␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬ATOM ␈↓↓␈↓αthen␈↓↓ ␈↓αat␈↓↓␈αεeval[␈↓αad␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬EQ ␈↓↓␈↓αthen␈↓↓  eval[␈↓αad␈↓↓␈α∧e, a] = eval[␈↓αadd␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬QUOTE ␈↓↓␈↓αthen␈↓↓ ␈↓αad␈↓↓␈α∧e␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬COND ␈↓↓␈↓αthen␈↓↓ evcon[␈↓αd␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬LIST ␈↓↓␈↓αthen␈↓↓ mapcar[␈↓αd␈↓↓␈α∧e, λx: eval[x, a]]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ eval[␈↓αd␈↓↓␈α∧assoc[␈↓αa␈↓↓␈α∧e, a] . ␈↓αd␈↓↓␈α∧e, a]]␈↓
␈↓ ↓H␈↓        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧e = ␈↓¬LAMBDA ␈↓↓␈↓αthen␈↓↓  eval[␈↓αadda␈↓↓␈α∧e, prup[␈↓αada␈↓↓␈α∧e, mapcar[␈↓αd␈↓↓␈α∧e, λx: eval[x, a]]] * a]␈↓
␈↓ ↓H␈↓        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧e = ␈↓¬LABEL ␈↓↓␈↓αthen␈↓↓ eval[␈↓αadda␈↓↓␈α∧e . ␈↓αd␈↓↓␈α∧e,  [␈↓αada␈↓↓␈α∧e . ␈↓αa␈↓↓␈α∧e] . a]␈↓,

␈↓ ↓H␈↓where the auxiliary function ␈↓↓evcon␈↓ is defined by

␈↓ ↓H␈↓␈↓ β∪␈↓↓evcon[u, a] ← ␈↓αif␈↓↓ eval[␈↓αaa␈↓↓␈α∧u, a] ␈↓αthen␈↓↓ eval[␈↓αada␈↓↓␈α∧u, a]  ␈↓αelse␈↓↓ evcon[␈↓αd␈↓↓␈α∧u, a]␈↓, 

␈↓ ↓H␈↓and␈α
the␈α
auxiliary␈αfunction␈α
␈↓↓prup␈↓␈α
used␈αfor␈α
pairing␈α
up␈α
the␈αelements␈α
of␈α
two␈αlists␈α
of␈α
equal␈α
length␈αis
␈↓ ↓H␈↓defined by

␈↓ ↓H␈↓␈↓ βP␈↓↓prup[u, v] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ [␈↓αa␈↓↓␈α∧u . ␈↓αa␈↓↓␈α∧v] . prup[␈↓αd␈↓↓␈α∧u,␈↓αd␈↓↓␈α∧v]␈↓. 

␈↓ ↓H␈↓        The␈αway␈α␈↓↓eval␈↓␈α
works␈αshould␈αbe␈α
clear.␈α Atoms␈αare␈α
either␈αimmediately␈αevaluable␈α
or␈αhave␈αto␈α
be
␈↓ ↓H␈↓looked␈α⊃up␈α⊃on␈α⊃the␈α⊃list␈α⊃␈↓↓a;␈↓␈α⊃expressions␈α⊃whose␈α⊃first␈α⊃term␈α⊃is␈α⊃one␈α⊃of␈α⊃the␈α⊃elementary␈α⊃functions␈α⊂are
␈↓ ↓H␈↓evaluated␈α∞by␈α∞performing␈α
the␈α∞indicated␈α∞operation␈α
on␈α∞the␈α∞result␈α
of␈α∞evaluating␈α∞the␈α∞arguments;␈α
␈↓↓list␈↓
␈↓ ↓H␈↓has␈α∞to␈α
be␈α∞handled␈α
specially,␈α∞because␈α
it␈α∞has␈α
an␈α∞indefinite␈α
number␈α∞of␈α
arguments;␈α∞conditionals␈α
are
␈↓ ↓H␈↓handled␈α
by␈α
an␈α
auxiliary␈α
function␈α
that␈αevaluates␈α
the␈α
terms␈α
in␈α
the␈α
right␈α
order;␈αquoted␈α
S-expressions
␈↓ ↓H␈↓are␈α∞trivial;␈α∞non-elementary␈α∞functions␈α∞have␈α∞their␈α∂definitions␈α∞looked␈α∞up␈α∞on␈α∞␈↓↓a␈↓␈α∞and␈α∂substituted␈α∞for
␈↓ ↓H␈↓their␈αnames;␈αwhen␈αa␈αfunction␈αis␈αspecified␈αby␈αa␈αλ,␈αthe␈αinner␈αexpression␈αis␈αevaluated␈αwith␈αa␈α
new␈α␈↓↓a␈↓
␈↓ ↓H␈↓which␈α⊂is␈α⊂obtained␈α⊂by␈α⊃evaluating␈α⊂the␈α⊂arguments␈α⊂and␈α⊂pairing␈α⊃them␈α⊂up␈α⊂with␈α⊂the␈α⊃variables␈α⊂and
␈↓ ↓H␈↓putting␈αthem␈αon␈αthe␈αfront␈αof␈αthe␈αold␈α␈↓↓a,␈↓␈α and␈αfinally,␈α ␈↓↓label␈↓␈αis␈αhandled␈αby␈αpairing␈αthe␈αname␈αof␈αthe
␈↓ ↓H␈↓70␈↓ ¬cCHAPTER IV␈↓ H


␈↓ ↓H␈↓function␈α∀with␈α∪the␈α∀expression␈α∪on␈α∀␈↓↓a␈↓␈α∀and␈α∪replacing␈α∀the␈α∪whole␈α∀function␈α∪by␈α∀the␈α∀λ-part.␈α∪ This
␈↓ ↓H␈↓simplified␈α
␈↓↓eval␈↓␈α
makes␈α
no␈α
provision␈α
for␈α
using␈α
LISP␈α
functions␈α
defined␈α
by␈α
␈↓¬DE,␈α
␈↓because␈α∞that␈α
would
␈↓ ↓H␈↓involve␈α∪looking␈α∪them␈α∩up␈α∪on␈α∪property␈α∩lists,␈α∪which␈α∪is␈α∩not␈α∪in␈α∪the␈α∩spirit␈α∪of␈α∪this␈α∩mathematical
␈↓ ↓H␈↓discussion.



␈↓ ↓H␈↓2.  ␈↓αIntroduction to Compiling LISP.␈↓


␈↓ ↓H␈↓        Compiling␈αis␈αan␈αimportant␈αexample␈αof␈αsymbolic␈αcomputation␈αand␈αhas␈αreceived␈αmuch␈αstudy.
␈↓ ↓H␈↓Much␈α
of␈α
the␈α
study␈α
has␈α
been␈α
devoted␈α
to␈α
parsing␈α
which␈α
is␈α
essentially␈α
the␈α
transformation␈α
of␈αan␈α
input
␈↓ ↓H␈↓string␈α⊂in␈α⊂the␈α∂source␈α⊂language␈α⊂into␈α∂an␈α⊂internal␈α⊂form.␈α∂ The␈α⊂internal␈α⊂form␈α∂used␈α⊂depends␈α⊂on␈α∂the
␈↓ ↓H␈↓compiler.␈α⊂ Sometimes␈α⊂it␈α⊂is␈α⊂Polish␈α⊂prefix␈α⊂or␈α∂postfix␈α⊂notation,␈α⊂sometimes␈α⊂it␈α⊂is␈α⊂list␈α⊂structure,␈α∂and
␈↓ ↓H␈↓sometimes it consists of entries in a collection of tables.

␈↓ ↓H␈↓        When␈αinternal␈αnotation␈αLISP␈αis␈αbeing␈αcompiled,␈αthe␈αparsing␈αis␈αtrivial,␈αbecause␈αthe␈αinput␈αis
␈↓ ↓H␈↓S-expressions␈α
and␈αthe␈α
internal␈α
form␈αwanted␈α
is␈α
list␈αstructure,␈α
so␈αwhat␈α
parsing␈α
there␈αis␈α
is␈α
done␈αby
␈↓ ↓H␈↓the␈α∞ordinary␈α∞LISP␈α∞␈↓↓read␈↓␈α∂routine.␈α∞ Therefore,␈α∞compilers␈α∞can␈α∂be␈α∞very␈α∞compact␈α∞and␈α∂transparent␈α∞in
␈↓ ↓H␈↓structure,␈αand␈α
we␈αcan␈α
concentrate␈αour␈α
attention␈αon␈αthe␈α
code␈αgeneration␈α
phase.␈α This␈α
is␈αas␈αit␈α
should
␈↓ ↓H␈↓be,␈α
because,␈αin␈α
my␈αopinion,␈α
parsing␈αis␈α
basically␈α
a␈αside␈α
issue␈αin␈α
compiling,␈αand␈α
code␈α
generation␈αis
␈↓ ↓H␈↓the matter of main scientific interest.

␈↓ ↓H␈↓        We␈α
shall␈αdescribe␈α
two␈α
compilers␈αin␈α
this␈αchapter␈α
called␈α
LCOM0␈αand␈α
LCOM4␈αwhich␈α
compile
␈↓ ↓H␈↓S-expression␈αLISP␈αinto␈αmachine␈α
language␈αfor␈αthe␈αPDP-10␈α
computer␈αaccording␈αto␈αthe␈α
conventions
␈↓ ↓H␈↓of␈α⊃MACLISP.␈α⊃ For␈α⊃now␈α∩we␈α⊃shall␈α⊃take␈α⊃these␈α∩conventions␈α⊃for␈α⊃granted.␈α⊃ Before␈α∩describing␈α⊃the
␈↓ ↓H␈↓compilers, we must describe these conventions.

␈↓ ↓H␈↓        The␈αtarget␈αlanguage␈αis␈αcalled␈αLAP␈αfor␈αLISP␈αassembly␈αprogram.␈α Each␈αfunction␈αis␈αcompiled
␈↓ ↓H␈↓separately␈αinto␈αa␈αseparate␈αLAP␈αprogram,␈αand␈αthese␈αprograms␈αare␈αwritten␈αonto␈αa␈αdisk␈αfile.␈α These
␈↓ ↓H␈↓files␈α∂can␈α∂later␈α∂be␈α∞read␈α∂into␈α∂a␈α∂LISP␈α∞core␈α∂image␈α∂and␈α∂assembled␈α∞in␈α∂place␈α∂by␈α∂the␈α∂LAP␈α∞assembler
␈↓ ↓H␈↓which␈αis␈αpart␈αof␈αthe␈αLISP␈αruntime␈αroutines.␈α
 The␈αcompiler,␈αon␈αthe␈αother␈αhand,␈αis␈αa␈αseparate␈α
LISP
␈↓ ↓H␈↓core␈αimage␈αthat␈αcan␈αbe␈αinstructed␈αto␈αcompile␈αseveral␈αinput␈αfiles.␈α For␈αan␈αinput␈αfile␈αcalled␈α<name>,
␈↓ ↓H␈↓it␈α∞produces␈α∞an␈α∞output␈α
file␈α∞called␈α∞<name>.LAP.␈α∞ All␈α∞this␈α
is␈α∞specific␈α∞to␈α∞the␈α∞PDP-10␈α
time-sharing
␈↓ ↓H␈↓system␈αand␈αfortunately␈αworks␈αthe␈αsame␈αwhether␈αthe␈αtime-sharing␈αsystem␈αis␈αthe␈αD.E.C.␈αsystem,␈αthe
␈↓ ↓H␈↓Stanford system, or TENEX.

␈↓ ↓H␈↓        The␈αLAP␈αprogram␈αproduced␈αis␈αa␈αlist␈αof␈αwords;␈αthe␈αlast␈αword␈αis␈α␈↓¬NIL␈↓,␈αand␈αthe␈αfirst␈αword␈αis␈αa
␈↓ ↓H␈↓header␈α
of␈α
the␈α
form␈α
␈↓¬(LAP␈α␈↓↓fname␈↓¬␈α
SUBR)␈↓␈α
where␈α
␈↓↓fname␈↓␈α
is␈αthe␈α
name␈α
of␈α
the␈α
function␈α
compiled.␈α This
␈↓ ↓H␈↓header␈α
tells␈α
the␈α
DSKIN␈α
program␈α
that␈α
it␈α∞should␈α
read␈α
S-expressions␈α
till␈α
it␈α
comes␈α
to␈α
␈↓¬NIL␈↓␈α∞and␈α
then
␈↓ ↓H␈↓submit␈αwhat␈α
it␈αhas␈α
collected␈αto␈α
the␈αLAP␈α
assembler␈αwhich␈α
will␈αassemble␈α
it␈αinto␈α
core.␈α The␈α
rest␈αof
␈↓ ↓H␈↓the words are either atoms representing labels or lists representing single PDP-10 instructions.
␈↓ ↓H␈↓␈↓ ¬cCHAPTER IV␈↓ *71


␈↓ ↓H␈↓3.  ␈↓αSome facts about the PDP-10.␈↓


␈↓ ↓H␈↓        The following facts about the PDP-10 may be of use:

␈↓ ↓H␈↓        The␈αPDP-10␈αhas␈αa␈α36␈αbit␈αword␈αand␈α
an␈α18␈αbit␈αaddress.␈α In␈αinstructions␈αand␈αin␈α
accumulators
␈↓ ↓H␈↓used␈α∩as␈α⊃index␈α∩registers␈α⊃the␈α∩address␈α∩is␈α⊃found␈α∩in␈α⊃the␈α∩right␈α∩part␈α⊃of␈α∩the␈α⊃word␈α∩where␈α∩the␈α⊃least
␈↓ ↓H␈↓significant bits in arithmetic reside.

␈↓ ↓H␈↓        There␈α
are␈α
16␈α
general␈α
registers␈α
which␈α
serve␈α
simultaneously␈α
 as␈α
accumulators␈α
 (receiving␈αthe
␈↓ ↓H␈↓results␈αof␈αarithmetic␈αoperations),␈αindex␈αregisters␈α(modifying␈αthe␈αnominal␈αaddresses␈αof␈α instructions
␈↓ ↓H␈↓to␈α
 form␈α
effective␈α
addresses),␈α
and␈α
as␈α
the␈α
first␈α
16␈α
registers␈α
of␈α
memory␈α
(if␈α
the␈α
effective␈α
address␈α
of␈α
 an
␈↓ ↓H␈↓instruction␈α
 is␈α less␈α
 than␈α 16,␈α
 then␈α the␈α
instruction␈αuses␈α
the␈αcorresponding␈α
general␈αregister␈α
as␈αits
␈↓ ↓H␈↓operand.)

␈↓ ↓H␈↓        All␈α
instructions␈α
have␈α
the␈α
same␈α
format␈α
and␈α
are␈α
written␈α
for␈α
the␈α
LAP␈α
assembly␈α
program␈α
in␈α
the
␈↓ ↓H␈↓form

␈↓ ↓H␈↓        (<op name> <accumulator> <address> <index register>).

␈↓ ↓H␈↓Thus␈α ␈↓¬(MOVE␈α1␈α
3␈αP)␈↓␈α causes␈αaccumulator  1␈α
 to␈αreceive␈αthe␈αcontents␈α
of␈αa␈α memory␈α
 register␈αwhose
␈↓ ↓H␈↓address␈α
is  3+c(P),␈α
i.e.␈α
3+<the␈α
contents␈α
of␈α
general␈αregister␈α
P>.␈α
 <address>␈α
may␈α
be␈α
a␈α
number,␈αa␈α
label,
␈↓ ↓H␈↓or␈α
an␈α
S-expression␈α
constant␈αin␈α
the␈α
form␈α
␈↓¬(QUOTE␈α␈↓↓e␈↓¬)␈↓␈α
where␈α
␈↓↓e␈↓␈α
is␈αan␈α
S-expression.␈α
 The␈α
latter␈αallows␈α
a
␈↓ ↓H␈↓quoted␈α⊃S-expression␈α⊃to␈α⊃be␈α⊃loaded␈α⊃into␈α⊃accumulator  1␈α⊃by␈α⊃the␈α⊃instruction␈α⊃ ␈↓¬(MOVEI 1 (QUOTE ␈↓↓e␈↓¬))␈↓.
␈↓ ↓H␈↓An␈αaddtional␈α
form␈αthat␈α
appears␈αin␈α
the␈αaddress␈α
field␈αfor␈α
some␈αinstructions␈α
is␈α␈↓¬(% 0 0 ␈↓↓m␈↓¬␈α
␈↓↓m␈↓¬)␈↓␈α.␈α This␈α
is
␈↓ ↓H␈↓a␈α
literal␈αwith␈α
value␈α
a␈αword␈α
containing␈α␈↓↓m␈↓␈α
in␈α
the␈αlefthand␈α
side␈αand␈α
␈↓↓n␈↓␈α
in␈αthe␈α
righthand␈αside.␈α
 Which
␈↓ ↓H␈↓form of <address> is meaningful depends on the instruction.

␈↓ ↓H␈↓        To␈α
determine␈α
the␈αeffective␈α
address␈α
of␈αan␈α
instruction␈α
the␈αfollowing␈α
rules␈α
apply.␈α
 The␈αvalue
␈↓ ↓H␈↓of␈α<address>␈α
is␈αcombined␈αwith␈α
the␈αcontents␈αof␈α
the␈αindex␈αregister␈α
to␈αform␈αa␈α
direct␈αaddress.␈α
 If␈αno
␈↓ ↓H␈↓index␈αregister␈αis␈αspecified,␈αthen␈αjust␈αthe␈αvalue␈αof␈α<address>␈αis␈αused.␈α If␈αan␈α@␈αoccurs␈αin␈αthe␈αlist␈αas␈α
a
␈↓ ↓H␈↓separate␈αsymbol,␈α then␈αthe␈αmemory␈αreference␈αis␈αindirect,␈αi.e.␈αthe␈αeffective␈αaddress␈αis␈αthe␈αcontents␈α
of
␈↓ ↓H␈↓the␈α⊂right␈α⊂half␈α⊃of␈α⊂the␈α⊂word␈α⊃ directly␈α⊂ addressed␈α⊂ by␈α⊂ the␈α⊃ instruction␈α⊂(modified␈α⊂ by␈α⊃ the␈α⊂index
␈↓ ↓H␈↓register and indirect bit of that word).

␈↓ ↓H␈↓        In␈α∞the␈α∞following␈α∞description␈α
of␈α∞some␈α∞instructions␈α∞useful␈α
in␈α∞constructing␈α∞the␈α∞compiler,␈α
<ef>
␈↓ ↓H␈↓denotes the effective address of an instruction and ac denotes the accumulator.

␈↓ ↓H␈↓␈↓ αHMOVE ␈↓ ¬(c(ac) ← c(<ef>)
␈↓ ↓H␈↓␈↓ αHMOVEI ␈↓ ¬(c(ac) ← <ef>
␈↓ ↓H␈↓␈↓ αHMOVEM ␈↓ ¬(c(<ef>) ← c(ac)
␈↓ ↓H␈↓␈↓ αHHLRZ ␈↓ ¬(right half of c(ac) ← left half of c(<ef>)
␈↓ ↓H␈↓␈↓ αHHRRZ ␈↓ ¬(right half of c(ac) ← right half of c(<ef>)
␈↓ ↓H␈↓␈↓ αH␈↓ β8(These two are used indirectly for  car  and  cdr  respectively.)
␈↓ ↓H␈↓␈↓ αHADD ␈↓ ¬(c(ac) ← c(ac) + c(<ef>)
␈↓ ↓H␈↓␈↓ αHSUB ␈↓ ¬(c(ac) ← c(ac) - c(<ef>)
␈↓ ↓H␈↓␈↓ αHJRST ␈↓ ¬(go to <ef>
␈↓ ↓H␈↓␈↓ αHJUMPE ␈↓ ¬(if c(ac) = 0 then go to <ef>
␈↓ ↓H␈↓72␈↓ ¬cCHAPTER IV␈↓ H


␈↓ ↓H␈↓␈↓ αHJUMPN ␈↓ ¬(if c(ac) ≠ 0 then go to <ef>
␈↓ ↓H␈↓␈↓ αHCAME ␈↓ ¬(if c(ac) = c(<ef>) then <skip next instruction>
␈↓ ↓H␈↓␈↓ αHCAMN ␈↓ ¬(if c(ac) ≠ c(<ef>) then <skip next instruction>
␈↓ ↓H␈↓␈↓ αHPUSH ␈↓ ¬(c(c(right␈αhalf␈αof␈αac))␈α←␈αc(<ef>);␈αthe␈αcontents␈αof␈αeach
␈↓ ↓H␈↓␈↓ ¬(half␈α
of␈αac␈α
is␈α
increased␈αby␈α
one␈α
and␈αif␈α
the␈αcontents␈α
of
␈↓ ↓H␈↓␈↓ ¬(the␈α∞left␈α∞half␈α∞is␈α∞then␈α∞ 0,␈α∞a␈α∞stack␈α∞overflow␈α∞interrupt
␈↓ ↓H␈↓␈↓ ¬(occurs.␈α
 (PUSH␈α
P␈α
ac)␈α
is␈α
used␈α
in␈α
LISP␈α
to␈α
put␈α
c(ac)
␈↓ ↓H␈↓␈↓ ¬(on the stack.
␈↓ ↓H␈↓␈↓ αHPOP ␈↓ ¬(c(<ef>)␈α
←c(c(right␈α∞half␈α
of␈α
ac));␈α∞the␈α
contents␈α∞of␈α
each
␈↓ ↓H␈↓␈↓ ¬(half␈α∞of␈α∞ac␈α∞are␈α∞then␈α∞decreased␈α∞by␈α∞1.␈α∞ This␈α∂may␈α∞be
␈↓ ↓H␈↓␈↓ ¬(used␈α∩for␈α⊃removing␈α∩the␈α∩top␈α⊃element␈α∩of␈α∩the␈α⊃stack.
␈↓ ↓H␈↓␈↓ ¬(Thus␈α(POP␈αP␈α
1)␈αputs␈αthe␈α
top␈αelement␈αof␈α
the␈αstack
␈↓ ↓H␈↓␈↓ ¬(in␈αaccumulator␈α1.␈α The␈αi-th␈αelement␈αof␈αthe␈α
stack␈αis
␈↓ ↓H␈↓␈↓ ¬(obtained by (MOVE 1 @ i P).
␈↓ ↓H␈↓␈↓ αHPOPJ ␈↓ ¬((POPJ P) is used for returning from a subroutine

␈↓ ↓H␈↓        These␈α∞instructions␈α∞are␈α∞adequate␈α∞for␈α∞compiling␈α∂basic␈α∞LISP␈α∞code␈α∞with␈α∞ the␈α∞addition␈α∂of␈α∞the
␈↓ ↓H␈↓subroutine␈αcalling␈αpseudo-instrucion.␈α The␈αform␈αof␈αthis␈αinstruction␈αis␈α␈↓¬(CALL ␈↓↓n␈↓¬␈α(QUOTE ␈↓<subr>␈↓¬))␈↓␈α.␈αIt
␈↓ ↓H␈↓is␈αused␈αfor␈αcalling␈αthe␈αLISP␈αsubroutine␈α<subr>␈αwith␈α ␈↓↓n␈↓␈αarguments.␈α  The␈α convention␈α is␈αthat␈αthe
␈↓ ↓H␈↓arguments␈αwill␈αbe␈αstored␈αin␈αsuccessive␈αaccumulators␈αbeginning␈αwith␈αaccumulator␈α 1,␈αand␈αthe␈αresult
␈↓ ↓H␈↓will␈α be␈α returned␈α in␈α accumulator  1.␈α  In␈αparticular␈αthe␈αfunctions␈α ␈↓¬ATOM␈α␈↓␈αand␈α ␈↓¬CONS␈α␈↓␈αare␈αcalled
␈↓ ↓H␈↓with␈α
 ␈↓¬(CALL 1 (QUOTE ATOM))␈↓␈α
 and␈α
 ␈↓¬(CALL 2 (QUOTE CONS))␈↓␈α
  respectively.␈α
 Programs␈α∞produced␈α
by
␈↓ ↓H␈↓you␈α
 will␈αbe␈α
called␈αsimilarly␈α
when␈αtheir␈α
names␈αare␈α
referred␈αto.␈α
 The␈αdetails␈α
of␈αhow␈α
␈↓¬CALL␈α␈↓works␈α
are
␈↓ ↓H␈↓unimportant␈α∪here;␈α∪it␈α∪actually␈α∪traps␈α∪to␈α∪a␈α∪machine␈α∪language␈α∪routine␈α∪that␈α∪checks␈α∪whether␈α∩the
␈↓ ↓H␈↓function␈αis␈αbeing␈αtraced␈αand␈αwhich␈αcan␈αreplace␈αthe␈α␈↓¬CALL␈α␈↓by␈α␈↓¬PUSHJ␈α␈↓for␈αgreater␈αspeed␈αwhen␈αtracing
␈↓ ↓H␈↓is definitely not wanted.

␈↓ ↓H␈↓        There␈α
are␈α
minor␈α
modifications␈αin␈α
the␈α
form␈α
of␈α
some␈αof␈α
the␈α
instructions␈α
for␈α
compiling␈αcode
␈↓ ↓H␈↓for␈α⊂the␈α∂LISP1.6␈α⊂assembler.␈α⊂ These␈α∂include␈α⊂the␈α∂calling␈α⊂instruction␈α⊂which␈α∂has␈α⊂the␈α⊂form␈α∂␈↓¬(CALL ␈↓↓n␈↓¬
␈↓ ↓H␈↓¬(QUOTE ␈↓<subr>␈↓¬) S)␈↓␈α⊃,␈α⊃the␈α∩form␈α⊃of␈α⊃the␈α⊃special␈α∩literal␈α⊃which␈α⊃is␈α⊃␈↓¬(C ␈↓↓m␈↓¬␈α∩0 ␈↓↓n␈↓¬␈α⊃0)␈↓␈α⊃and␈α⊃the␈α∩manner␈α⊃of
␈↓ ↓H␈↓indicating␈α∞indirect␈α∞addressing,␈α∞which␈α∞is␈α∞to␈α∞attach␈α∞the␈α∞@␈α∞sign␈α∞to␈α∞the␈α∞operation␈α∞name␈α∞rather␈α
than
␈↓ ↓H␈↓putting in as a separate element of the list.



␈↓ ↓H␈↓4.  ␈↓αCode produced by LISP compilers.␈↓


␈↓ ↓H␈↓        We␈αwill␈αdiscuss␈α
two␈αcompilers,␈αa␈αsimple␈α
one␈αcalled␈αLCOM0␈α
and␈αa␈αmore␈αoptimising␈α
compiler
␈↓ ↓H␈↓called␈αLCOM4.␈α LCOM4␈αproduces␈α
about␈αhalf␈αas␈αmany␈αinstructions␈α
for␈αa␈αgiven␈αfunction␈α
as␈αdoes
␈↓ ↓H␈↓LCOM0.␈α⊃Besides␈α⊃these,␈α⊂there␈α⊃are␈α⊃the␈α⊂standard␈α⊃PDP-10␈α⊃LISP␈α⊂compiler␈α⊃written␈α⊃at␈α⊃M.I.T.␈α⊂ by
␈↓ ↓H␈↓Richard␈α⊂Greenblatt␈α⊂and␈α⊂Stuart␈α⊂Nelson␈α⊃and␈α⊂modified␈α⊂by␈α⊂Whitfield␈α⊂Diffie␈α⊂and␈α⊃the␈α⊂MACLISP
␈↓ ↓H␈↓compiler NCOMPLR.

␈↓ ↓H␈↓        At␈α
the␈α
end␈α
of␈α
this␈α
section␈α
are␈α
examples␈α
of␈α
the␈α
output␈α
of␈α
each␈α
of␈α
the␈α
compilers␈α
mentioned
␈↓ ↓H␈↓above for the file containing:
␈↓ ↓H␈↓␈↓ ¬cCHAPTER IV␈↓ *73


␈↓ ↓H␈↓                ␈↓¬(DEFPROP DROP␈↓
␈↓ ↓H␈↓                 ␈↓¬(LAMBDA(X)␈↓
␈↓ ↓H␈↓                  ␈↓¬(COND ((NULL X) NIL) (T (CONS (LIST (CAR X)) (DROP (CDR X))))))␈↓
␈↓ ↓H␈↓                ␈↓¬EXPR)␈↓

␈↓ ↓H␈↓        The following comments are with regard to these examples.

␈↓ ↓H␈↓        1.␈α
Note␈α
 that␈α
all␈α
four␈α
compilers␈α
produce␈αthe␈α
same␈α
first␈α
line␈α
of␈α
heading.␈α
 This␈α
is␈αnecessary␈α
for
␈↓ ↓H␈↓the␈α⊃LAP␈α⊃assembly␈α⊂program␈α⊃ which␈α⊃ also␈α⊃requires␈α⊂ the␈α⊃ ␈↓¬NIL␈↓ ␈α⊃at␈α⊂the␈α⊃end␈α⊃as␈α⊃punctuation.␈α⊂ The
␈↓ ↓H␈↓standard␈αcompiler␈α
and␈αNCOMPLR␈αuse␈α
a␈αfunction␈αcalled␈α
 ␈↓¬XCONS ␈α␈↓that␈αhas␈α
 the␈α same␈α
 effect␈α as
␈↓ ↓H␈↓␈↓¬CONS␈α␈↓␈αexcept␈α that␈α
 it␈αreceives␈αits␈αarguments␈αin␈α
the␈αreverse␈αorder␈αwhich␈αis␈α
sometimes␈αconvenient.
␈↓ ↓H␈↓This␈αrequires,␈αof␈αcourse,␈αthat␈αthe␈αcompiler␈αbe␈αsmart␈αenough␈αto␈αdecide␈αwhere␈αit␈αis␈αmore␈αconvenient
␈↓ ↓H␈↓to␈α
put␈α
the␈α
arguments␈α
of␈α
the␈α␈↓↓cons␈↓␈α
function.␈α
 They␈α
also␈α
use␈α
␈↓¬NCONS␈α
␈↓rather␈αthan␈α
␈↓¬LIST␈α
␈↓␈α
to␈α
form␈α
a␈αlist␈α
of
␈↓ ↓H␈↓one element.

␈↓ ↓H␈↓        2.␈α∂The␈α⊂two␈α∂compilers,␈α⊂LCOM0␈α∂and␈α⊂LCOM4,␈α∂are␈α⊂similar␈α∂in␈α⊂structure,␈α∂but␈α⊂LCOM4,␈α∂the
␈↓ ↓H␈↓better one, which is twice as long, uses the following optimisations.

␈↓ ↓H␈↓        2.1.␈α∂When␈α⊂the␈α∂argument␈α⊂of␈α∂␈↓¬CAR␈α⊂␈↓or␈α∂␈↓¬CDR␈α∂␈↓is␈α⊂a␈α∂variable,␈α⊂it␈α∂compiles␈α⊂a␈α∂ ␈↓¬(HLRZ 1 @  ␈↓↓i␈↓¬␈α⊂P)␈↓␈α∂ or
␈↓ ↓H␈↓␈↓¬(HRRZ 1 @  ␈↓↓i␈↓¬␈αP)␈↓␈α which␈αgets␈αthe␈αresult␈αthrough␈αthe␈αstack␈αwithout␈αfirst␈αcompiling␈αthe␈αargument␈αinto
␈↓ ↓H␈↓an accumulator.

␈↓ ↓H␈↓        2.2.␈α
When␈α
it␈α
has␈α
to␈α
set␈α
up␈α
the␈α
arguments␈α
of␈α
a␈α
function␈α
 in␈α
 the␈α
accumulators,␈α
 in␈αgeneral,␈α
the
␈↓ ↓H␈↓program␈α
must␈α
compute␈α
the␈α
arguments␈α
one␈α
at␈α
a␈αtime␈α
and␈α
save␈α
them␈α
on␈α
the␈α
stack,␈α
and␈α
then␈αload
␈↓ ↓H␈↓the␈α∞ accumulators␈α∞from␈α∞the␈α∞stack.␈α∞ However,␈α∞if␈α∂one␈α∞of␈α∞the␈α∞arguments␈α∞is␈α∞a␈α∞variable,␈α∞is␈α∂a␈α∞quoted
␈↓ ↓H␈↓expression,␈αor␈αcan␈αbe␈αobtained␈αfrom␈αa␈αvariable␈αby␈αa␈α chain␈α of␈α ␈↓¬CAR␈↓s ␈α and␈α  ␈↓¬CDR␈↓s,␈α then␈α it␈α need
␈↓ ↓H␈↓not␈αbe␈αcomputed␈α
until␈αthe␈αtime␈α
of␈αloading␈α accumulators␈α
 since␈α it␈α can␈α
 be␈α computed␈α using␈α
 only
␈↓ ↓H␈↓the accumulator in which it is wanted.

␈↓ ↓H␈↓        3.␈α⊂ The␈α⊂ Diffie␈α⊂ compiler␈α⊂ produces␈α⊂about␈α⊂10␈α⊂percent␈α⊂less␈α⊂code␈α⊂than␈α⊂LCOM4;␈α⊂the␈α∂main
␈↓ ↓H␈↓difference␈α∞seems␈α∞to␈α∂be␈α∞that␈α∞it␈α∂sometimes␈α∞notices␈α∞when␈α∂ it␈α∞ has␈α∞ an␈α∂ expression␈α∞that␈α∞it␈α∂will␈α∞need
␈↓ ↓H␈↓later.␈αSometimes␈αthis␈αfeature␈αleads␈αit␈α
astray.␈αFor␈αexample,␈αit␈αmay␈αsave␈α
 ␈↓αa␈↓␈α∧␈↓↓u␈↓␈α ␈αfor␈αlater␈αuse␈αat␈α
greater
␈↓ ↓H␈↓cost than re-computing it.

␈↓ ↓H␈↓        4.␈α∩ NCOMPLR␈α∩is␈α∩noted␈α∩particularly␈α∩for␈α∩its␈α∩efficient␈α∩code␈α∩for␈α∩numerical␈α∩computations.
␈↓ ↓H␈↓Hence␈α_the␈α_"N".␈α_   Except␈α_for␈α→some␈α_bookkeeping␈α_code␈α_initially,␈α_the␈α_Diffie␈α→compiler␈α_and
␈↓ ↓H␈↓NCOMPLR produce similar code for this example.
␈↓ ↓H␈↓74␈↓ ¬cCHAPTER IV␈↓ H


␈↓ ↓H␈↓******************************************************************



␈↓ ↓H␈↓LCOM0  produces the following code for the MACLISP LAP assembler.


␈↓ ↓H␈↓¬(LAP DROP SUBR) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(MOVE 1 0 P) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(MOVE 1 0 P) 
␈↓ ↓H␈↓¬(SUB P (% 0 0 1 1)) 
␈↓ ↓H␈↓¬(CALL 1 (QUOTE NULL)) 
␈↓ ↓H␈↓¬(JUMPE 1 G0003) 
␈↓ ↓H␈↓¬(MOVEI 1 0) 
␈↓ ↓H␈↓¬(JRST 0 G0002) 
␈↓ ↓H␈↓¬G0003 
␈↓ ↓H␈↓¬(MOVEI 1 (QUOTE T)) 
␈↓ ↓H␈↓¬(JUMPE 1 G0004) 
␈↓ ↓H␈↓¬(MOVE 1 0 P) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(MOVE 1 0 P) 
␈↓ ↓H␈↓¬(SUB P (% 0 0 1 1)) 
␈↓ ↓H␈↓¬(CALL 1 (QUOTE CAR)) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(MOVE 1 0 P) 
␈↓ ↓H␈↓¬(SUB P (% 0 0 1 1)) 
␈↓ ↓H␈↓¬(CALL 1 (QUOTE LIST)) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(MOVE 1 -1 P) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(MOVE 1 0 P) 
␈↓ ↓H␈↓¬(SUB P (% 0 0 1 1)) 
␈↓ ↓H␈↓¬(CALL 1 (QUOTE CDR)) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(MOVE 1 0 P) 
␈↓ ↓H␈↓¬(SUB P (% 0 0 1 1)) 
␈↓ ↓H␈↓¬(CALL 1 (QUOTE DROP)) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(MOVE 1 -1 P) 
␈↓ ↓H␈↓¬(MOVE 2 0 P) 
␈↓ ↓H␈↓¬(SUB P (% 0 0 2 2)) 
␈↓ ↓H␈↓¬(CALL 2 (QUOTE CONS)) 
␈↓ ↓H␈↓¬(JRST 0 G0002) 
␈↓ ↓H␈↓¬G0004 
␈↓ ↓H␈↓¬G0002 
␈↓ ↓H␈↓¬(SUB P (% 0 0 1 1)) 
␈↓ ↓H␈↓¬(POPJ P) 
␈↓ ↓H␈↓¬NIL 
␈↓ ↓H␈↓␈↓ ¬cCHAPTER IV␈↓ *75


␈↓ ↓H␈↓******************************************************************



␈↓ ↓H␈↓LCOM4  produces the following code for the MACLISP LAP assembler.



␈↓ ↓H␈↓¬(LAP DROP SUBR) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(MOVE 1 0 P) 
␈↓ ↓H␈↓¬(JUMPE 1 G0003) 
␈↓ ↓H␈↓¬(HLRZ 1 @ 0 P) 
␈↓ ↓H␈↓¬(CALL 1 (QUOTE LIST)) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(HRRZ @ 1 -1 P) 
␈↓ ↓H␈↓¬(CALL 1 (QUOTE DROP)) 
␈↓ ↓H␈↓¬(MOVE 2 1) 
␈↓ ↓H␈↓¬(MOVE 1 0 P) 
␈↓ ↓H␈↓¬(SUB P (% 0 0 1 1)) 
␈↓ ↓H␈↓¬(CALL 2 (QUOTE CONS)) 
␈↓ ↓H␈↓¬G0003 
␈↓ ↓H␈↓¬(SUB P (% 0 0 1 1)) 
␈↓ ↓H␈↓¬(POPJ P) 
␈↓ ↓H␈↓¬NIL 



␈↓ ↓H␈↓******************************************************************



␈↓ ↓H␈↓The Diffie compiler produces the following code for the LISP1.6 assembler.


␈↓ ↓H␈↓¬(LAP DROP SUBR) 
␈↓ ↓H␈↓¬       (PUSH P 1) 
␈↓ ↓H␈↓¬       (JUMPE 1 TAG1) 
␈↓ ↓H␈↓¬       (HLRZ@ 1 0 P) 
␈↓ ↓H␈↓¬       (CALL 1 (E NCONS) S) 
␈↓ ↓H␈↓¬       (PUSH P 1) 
␈↓ ↓H␈↓¬       (HRRZ@ 1 -1 P) 
␈↓ ↓H␈↓¬       (CALL 1 (E DROP) S) 
␈↓ ↓H␈↓¬       (POP P 2) 
␈↓ ↓H␈↓¬       (CALL 2 (E XCONS) S) 
␈↓ ↓H␈↓¬ TAG1  (SUB P (C O 0 1 1)) 
␈↓ ↓H␈↓¬       (POPJ P) 
␈↓ ↓H␈↓¬       NIL 
␈↓ ↓H␈↓76␈↓ ¬cCHAPTER IV␈↓ H


␈↓ ↓H␈↓******************************************************************



␈↓ ↓H␈↓The MACLISP compiler, NCOMPLR,  produces the following code:

␈↓ ↓H␈↓        (The␈α∞pseudo-instruction␈α∞ARGS␈α∞tells␈α∞the␈α∞assembler␈α∞the␈α∞number␈α∞of␈α∞arguments␈α∂expected␈α∞by
␈↓ ↓H␈↓the␈α∞function.␈α∂ The␈α∞instruction␈α∂JSP␈α∞is␈α∂a␈α∞special␈α∂fast␈α∞function␈α∂call␈α∞done␈α∂by␈α∞jumping␈α∂rather␈α∞than
␈↓ ↓H␈↓going␈α⊃through␈α⊃the␈α⊃regular␈α⊃calling␈α∩mechanism.␈α⊃ T␈α⊃denotes␈α⊃an␈α⊃accumulator␈α⊃designated␈α∩to␈α⊃hold
␈↓ ↓H␈↓temporary values.)


␈↓ ↓H␈↓¬(LAP DROP SUBR) 
␈↓ ↓H␈↓¬(ARGS DROP (NIL . 1)) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(JSP T PDLNMK) 
␈↓ ↓H␈↓¬(JUMPE 1 G0001) 
␈↓ ↓H␈↓¬(HLRZ 1 @ 0 P) 
␈↓ ↓H␈↓¬(JSP T %NCONS) 
␈↓ ↓H␈↓¬(PUSH P 1) 
␈↓ ↓H␈↓¬(HRRZ 1 @ -1 P) 
␈↓ ↓H␈↓¬(CALL 1 'DROP) 
␈↓ ↓H␈↓¬(POP P 2) 
␈↓ ↓H␈↓¬(JSP T %XCONS) 
␈↓ ↓H␈↓¬G0001 
␈↓ ↓H␈↓¬(SUB P (% 0 0 1 1)) 
␈↓ ↓H␈↓¬(POPJ P) 
␈↓ ↓H␈↓¬NIL 
␈↓ ↓H␈↓␈↓ ¬cCHAPTER IV␈↓ *77


␈↓ ↓H␈↓5.  ␈↓αLCOM0.␈↓



␈↓ ↓H␈↓        The␈α∂following␈α∞is␈α∂an␈α∞annotated␈α∂listing␈α∞of␈α∂the␈α∞MACLISP␈α∂version␈α∞of␈α∂LCOM0␈α∂ in␈α∞external
␈↓ ↓H␈↓notation.  A listing in internal notation can be found in Appendix III.

␈↓ ↓H␈↓        ␈↓↓compl␈↓␈α∂is␈α∂the␈α∂user-callable␈α∂driver.␈α∂ It␈α∂is␈α∂a␈α∂FEXPR.␈α∂ It␈α∂takes␈α∂as␈α∂an␈α∂argument␈α∂a␈α∂single␈α∂file
␈↓ ↓H␈↓name.␈α⊂ EXPRs␈α⊂on␈α⊂a␈α⊂file␈α∂called␈α⊂FILNAM␈α⊂will␈α⊂be␈α⊂compiled␈α∂into␈α⊂LAP␈α⊂and␈α⊂written␈α⊂on␈α⊂the␈α∂file
␈↓ ↓H␈↓FILNAM.LAP.␈α⊃Other␈α⊃types␈α⊃of␈α⊃function␈α⊃definitions␈α⊃and␈α⊃non-definitions␈α⊃are␈α⊃simply␈α⊃copied␈α⊃to
␈↓ ↓H␈↓output.␈α It␈αis,␈αalas,␈αdependent␈αon␈αthe␈αI/O␈αstructure␈αof␈αthe␈αimplementation␈αand␈αneed␈αnot␈αbe␈αstudied
␈↓ ↓H␈↓carefully.  All the other functions are substantially independent of implementation.


␈↓ ↓H␈↓        FEXPER:
␈↓ ↓H␈↓        ␈↓↓compl file ← ␈↓
␈↓ ↓H␈↓          ␈↓↓[uwrite[], ␈↓                                                            ~Open a file for output
␈↓ ↓H␈↓           ␈↓↓apply[␈↓¬EREAD␈↓↓, file], ␈↓                                               ~Open input file
␈↓ ↓H␈↓           ␈↓↓select-disk-input[␈↓
␈↓ ↓H␈↓             ␈↓↓read-until-eof[with  z  do␈↓                                          ~Read each expression in file
␈↓ ↓H␈↓               ␈↓↓␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧z = ␈↓¬DEFUN␈↓↓ ∨ [␈↓αa␈↓↓␈α∧z = ␈↓¬DEFPROP␈↓↓ ∧ ␈↓αaddd␈↓↓␈α∧z = ␈↓¬EXPR␈↓↓] ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓                 ␈↓↓[␈↓αprog␈↓↓ [prog]␈↓
␈↓ ↓H␈↓                       ␈↓↓prog␈↓
␈↓ ↓H␈↓                        ␈↓↓← [␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧z = ␈↓¬DEFUN␈↓↓ ␈↓αthen␈↓↓ comp[␈↓αad␈↓↓␈α∧z, ␈↓αadd␈↓↓␈α∧z, ␈↓αaddd␈↓↓␈α∧z]␈↓
␈↓ ↓H␈↓                           ␈↓↓␈↓αelse␈↓↓ comp[␈↓αad␈↓↓␈α∧z, ␈↓αad␈↓↓␈α∧␈↓αadd␈↓↓␈α∧z, ␈↓αadd␈↓↓␈α∧␈↓αadd␈↓↓␈α∧z]]␈↓
␈↓ ↓H␈↓                       ␈↓↓unselect-tty ␈↓
␈↓ ↓H␈↓                         ␈↓↓select-disk-output mapc[print, prog]␈↓                    ~ Print out code in file
␈↓ ↓H␈↓                       ␈↓↓print <␈↓αad␈↓↓␈α∧z, length prog>]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ unselect-tty select-disk-output print z], ␈↓
␈↓ ↓H␈↓             ␈↓↓apply[␈↓¬UFILE␈↓↓, <␈↓αa␈↓↓␈α∧file, ␈↓¬LAP␈↓↓>], ␈↓                                ~Close and rename file
␈↓ ↓H␈↓             ␈↓↓␈↓¬ENDCOMP␈↓↓]]␈↓




␈↓ ↓H␈↓        ␈↓↓comp␈↓␈αcompiles␈αa␈αsingle␈α
function␈αdefinition,␈αreturning␈αa␈α
list␈αof␈αthe␈αLAP␈α
code␈αcorresponding
␈↓ ↓H␈↓to␈α⊂the␈α⊂definition.␈α⊂ ␈↓↓fn␈↓␈α⊂is␈α⊃the␈α⊂atomic␈α⊂name␈α⊂of␈α⊂the␈α⊃function␈α⊂being␈α⊂compiled.␈α⊂ ␈↓↓vars␈↓␈α⊂is␈α⊃the␈α⊂formal
␈↓ ↓H␈↓parameter list for the function.  ␈↓↓exp␈↓ is the function body.


␈↓ ↓H␈↓        ␈↓↓comp[fn, vars, exp] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓{length vars}[λn: ␈↓
␈↓ ↓H␈↓            ␈↓↓<<␈↓¬LAP␈↓↓, fn, ␈↓¬SUBR␈↓↓>>␈↓
␈↓ ↓H␈↓            ␈↓↓* mkpush[n, 1]␈↓
␈↓ ↓H␈↓            ␈↓↓* compexp[exp, -n, prup[vars, 1]]␈↓
␈↓ ↓H␈↓            ␈↓↓* <<␈↓¬SUB␈↓↓, ␈↓¬P␈↓↓, <␈↓¬%␈↓↓, 0, 0, n, n>>>␈↓
␈↓ ↓H␈↓            ␈↓↓* ␈↓¬((POPJ P) NIL)␈↓↓]␈↓
␈↓ ↓H␈↓78␈↓ ¬cCHAPTER IV␈↓ H


␈↓ ↓H␈↓        ␈↓↓prup␈↓␈α∞returns␈α∞an␈α∂A-LIST␈α∞formed␈α∞by␈α∞pairing␈α∂successive␈α∞elements␈α∞of␈α∞␈↓↓vars␈↓␈α∂with␈α∞consecutive
␈↓ ↓H␈↓integers beginning with ␈↓↓n.␈↓


␈↓ ↓H␈↓        ␈↓↓prup[vars, n] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧vars ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ [␈↓αa␈↓↓␈α∧vars . n] . prup[␈↓αd␈↓↓␈α∧vars, add1 n]␈↓




␈↓ ↓H␈↓        ␈↓↓mkpush␈↓␈α
returns␈α
a␈αlist␈α
of␈α
␈↓↓n␈↓␈α
␈↓¬(PUSH␈αP␈α
␈↓↓i␈↓¬)␈↓␈α
instructions,␈α
where␈α␈↓↓i␈↓␈α
runs␈α
from␈α
␈↓↓n␈↓␈αto␈α
␈↓↓m+n-1.␈↓␈α
 It␈αis␈α
used
␈↓ ↓H␈↓to push arguments onto the stack.


␈↓ ↓H␈↓        ␈↓↓mkpush[n, m] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ n < m ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ <␈↓¬PUSH␈↓↓, ␈↓¬P␈↓↓, m> . mkpush[n, add1 m]␈↓



␈↓ ↓H␈↓        ␈↓↓compexp␈↓␈α∩is␈α∪the␈α∩heart␈α∩of␈α∪LCOM0.␈α∩ It␈α∪determines␈α∩precisely␈α∩what␈α∪an␈α∩expression␈α∪is,␈α∩and
␈↓ ↓H␈↓compiles␈α⊃appropriate␈α⊃code␈α⊂for␈α⊃it.␈α⊃ It␈α⊂returns␈α⊃a␈α⊃list␈α⊃of␈α⊂that␈α⊃code.␈α⊃ ␈↓↓exp␈↓␈α⊂is␈α⊃the␈α⊃expression␈α⊃to␈α⊂be
␈↓ ↓H␈↓compiled.␈α ␈↓↓m␈↓␈αis␈αminus␈αthe␈αnumber␈αof␈αentries␈αon␈αthe␈αstack.␈αWhen␈αadded␈αto␈αa␈αvalue␈αretrieved␈αfrom
␈↓ ↓H␈↓the␈αA-LIST␈α␈↓↓vpr,␈↓␈αit␈αcan␈αbe␈αused␈αto␈αlocate␈αa␈αvariable␈αon␈αthe␈αstack.␈α ␈↓↓vpr␈↓␈αis␈αan␈αA-LIST,␈αassociating
␈↓ ↓H␈↓variable␈α⊂names␈α⊂with␈α⊂numbers␈α⊂which,␈α⊂when␈α⊂added␈α∂to␈α⊂␈↓↓m,␈↓␈α⊂give␈α⊂stack␈α⊂offsets.␈α⊂ Both␈α⊂␈↓↓m␈↓␈α⊂and␈α∂␈↓↓vpr␈↓
␈↓ ↓H␈↓maintain␈α∂these␈α∂definitions␈α∞throughout.␈α∂ ␈↓↓gensym[]␈↓␈α∂is␈α∂a␈α∞pseudo-function␈α∂of␈α∂no␈α∂arguments.␈α∞ Every
␈↓ ↓H␈↓time␈αit␈αis␈αcalled,␈αit␈αreturns␈αa␈αdifferent␈αsymbol.␈α The␈αpresence␈αof␈α␈↓↓gensym[]␈↓␈αmeans␈αthat␈αLCOM0␈α
and
␈↓ ↓H␈↓LCOM4␈α
are␈α
not␈α
pure␈αLISP␈α
so␈α
that␈α
the␈αtechniques␈α
of␈α
Chapter␈α
3␈α
cannot␈αbe␈α
used␈α
to␈α
prove␈αthat␈α
they
␈↓ ↓H␈↓meet␈α⊂their␈α∂specifications.␈α⊂ It␈α∂is␈α⊂possible␈α∂to␈α⊂eliminate␈α⊂the␈α∂use␈α⊂of␈α∂␈↓↓gensym,␈↓␈α⊂but␈α∂as␈α⊂of␈α⊂the␈α∂present
␈↓ ↓H␈↓writing,␈α
such␈α
version␈α
hasn't␈α
been␈α
written.␈α In␈α
any␈α
case,␈α
other␈α
unsolved␈α
problems␈α
remain␈αbefore␈α
one
␈↓ ↓H␈↓can␈α
give␈α
a␈α
first␈α
order␈αlogic␈α
proof␈α
of␈α
the␈α
correspondence␈αbetween␈α
␈↓↓eval␈↓␈α
and␈α
the␈α
code␈α
produced␈αby
␈↓ ↓H␈↓the compilers.


␈↓ ↓H␈↓        ␈↓↓compexp[exp, m, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧exp ␈↓αthen␈↓↓ ␈↓¬((MOVEI 1 0))␈↓↓␈↓                                              ~␈↓¬NIL␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ exp = ␈↓¬T␈↓↓ ␈↓αthen␈↓↓ ␈↓¬((MOVEI 1 (QUOTE T)))␈↓↓␈↓                             ~␈↓¬T␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ numberp exp ␈↓αthen␈↓↓ <<␈↓¬MOVEI␈↓↓, 1, <␈↓¬QUOTE␈↓↓, exp>>>␈↓                   ~number
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεexp ␈↓αthen␈↓↓ <<␈↓¬MOVE␈↓↓, 1, m + ␈↓αd␈↓↓␈α∧assoc[exp, vpr], ␈↓¬P␈↓↓>>␈↓           ~variable
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧exp = ␈↓¬AND␈↓↓ ∨ ␈↓αa␈↓↓␈α∧exp = ␈↓¬OR␈↓↓ ∨ ␈↓αa␈↓↓␈α∧exp = ␈↓¬NOT␈↓↓ ␈↓αthen␈↓↓ ␈↓            ~boolean expression
␈↓ ↓H␈↓            ␈↓↓{gensym[], gensym[]}[λl1, l2: ␈↓
␈↓ ↓H␈↓              ␈↓↓combool[exp, m, l1, ␈↓¬NIL␈↓↓, vpr]␈↓
␈↓ ↓H␈↓              ␈↓↓* <␈↓¬(MOVEI 1 (QUOTE T))␈↓↓, ␈↓
␈↓ ↓H␈↓                 ␈↓↓<␈↓¬JRST␈↓↓, 0, l2>, ␈↓
␈↓ ↓H␈↓                 ␈↓↓l1, ␈↓
␈↓ ↓H␈↓                 ␈↓↓␈↓¬(MOVEI 1 0)␈↓↓, ␈↓
␈↓ ↓H␈↓                 ␈↓↓l2>]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧exp = ␈↓¬COND␈↓↓ ␈↓αthen␈↓↓ comcond[␈↓αd␈↓↓␈α∧exp, m, gensym[], vpr]␈↓             ~␈↓¬COND ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧exp = ␈↓¬QUOTE␈↓↓ ␈↓αthen␈↓↓ <<␈↓¬MOVEI␈↓↓, 1, exp>>␈↓                         ~␈↓¬QUOTE ␈↓
␈↓ ↓H␈↓␈↓ ¬cCHAPTER IV␈↓ *79


␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧exp ␈↓αthen␈↓↓ ␈↓                                                    ~function call
␈↓ ↓H␈↓            ␈↓↓{length ␈↓αd␈↓↓␈α∧exp}[λn: ␈↓
␈↓ ↓H␈↓              ␈↓↓complis[␈↓αd␈↓↓␈α∧exp, m, vpr]␈↓
␈↓ ↓H␈↓              ␈↓↓* loadac[1 - n, 1]␈↓
␈↓ ↓H␈↓              ␈↓↓* <<␈↓¬SUB␈↓↓, ␈↓¬P␈↓↓, <␈↓¬%␈↓↓, 0, 0, n, n>>>␈↓
␈↓ ↓H␈↓              ␈↓↓* <<␈↓¬CALL␈↓↓, n, <␈↓¬QUOTE␈↓↓, ␈↓αa␈↓↓␈α∧exp>>>]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧exp = ␈↓¬LAMBDA␈↓↓ ␈↓αthen␈↓↓ ␈↓                                           ~λ-expression
␈↓ ↓H␈↓            ␈↓↓{length ␈↓αd␈↓↓␈α∧exp}[λn: ␈↓
␈↓ ↓H␈↓              ␈↓↓complis[␈↓αd␈↓↓␈α∧exp, m, vpr]␈↓
␈↓ ↓H␈↓              ␈↓↓* compexp[␈↓αadda␈↓↓␈α∧exp, m - n, prup[␈↓αada␈↓↓␈α∧exp, 1 - m] * vpr]␈↓
␈↓ ↓H␈↓              ␈↓↓* <<␈↓¬SUB␈↓↓, ␈↓¬P␈↓↓, <␈↓¬%␈↓↓, 0, 0, n, n>>>]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓¬NIL␈↓↓␈↓                                                                     ~oops!



␈↓ ↓H␈↓        ␈↓↓complis␈↓␈αcompiles␈αcode␈αto␈αevaluate␈αeach␈αexpression␈αin␈αa␈αlist␈αof␈αexpressions␈αand␈αto␈αpush␈αthose
␈↓ ↓H␈↓values␈α⊃onto␈α⊃the␈α⊃stack.␈α⊃ It␈α⊃returns␈α⊂a␈α⊃list␈α⊃of␈α⊃that␈α⊃code.␈α⊃ It␈α⊂is␈α⊃used␈α⊃to␈α⊃compile␈α⊃code␈α⊃to␈α⊂evaluate
␈↓ ↓H␈↓arguments to called functions or λ-expressions.  ␈↓↓u␈↓ is a list of expressions.


␈↓ ↓H␈↓        ␈↓↓complis[u, m, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ compexp[␈↓αa␈↓↓␈α∧u, m, vpr]␈↓
␈↓ ↓H␈↓                ␈↓↓* ␈↓¬((PUSH P 1))␈↓↓␈↓
␈↓ ↓H␈↓                ␈↓↓* complis[␈↓αd␈↓↓␈α∧u, sub1 m, vpr]␈↓




␈↓ ↓H␈↓␈↓↓loadac␈↓␈αreturns␈αa␈αlist␈αof␈α␈↓¬(MOVE␈α␈↓↓i␈↓¬␈α␈↓↓j␈↓¬␈αP)␈↓␈αinstructions,␈αloading␈αconsecutive␈αaccumulators␈αfrom␈αthe␈αtop␈αof
␈↓ ↓H␈↓the stack.  ␈↓↓k␈↓ indexes the accumulator loaded.  ␈↓↓n␈↓ indexes the stack offset.


␈↓ ↓H␈↓        ␈↓↓loadac[n, k] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ n > 0 ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ <␈↓¬MOVE␈↓↓, k, n, ␈↓¬P␈↓↓> . loadac[add1 n, add1 k]␈↓




␈↓ ↓H␈↓        ␈↓↓comcond␈↓␈αcompiles␈α
a␈α␈↓¬COND.␈α
␈↓␈α␈↓↓u␈↓␈α
is␈αa␈α
list␈αof␈α
clauses␈αin␈α
the␈α␈↓¬COND.␈α
␈↓␈α␈↓↓l␈↓␈α
is␈αa␈α
label␈αto␈α
be␈αemitted␈αat␈α
the
␈↓ ↓H␈↓end of all code for the ␈↓¬COND. ␈↓


␈↓ ↓H␈↓        ␈↓↓comcond[u, m, l, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ <l>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ {gensym[]}[λl1: ␈↓
␈↓ ↓H␈↓            ␈↓↓combool[␈↓αaa␈↓↓␈α∧u, m, l1, ␈↓¬NIL␈↓↓, vpr]␈↓
␈↓ ↓H␈↓80␈↓ ¬cCHAPTER IV␈↓ H


␈↓ ↓H␈↓            ␈↓↓* compexp[␈↓αada␈↓↓␈α∧u, m, vpr]␈↓
␈↓ ↓H␈↓            ␈↓↓* <<␈↓¬JRST␈↓↓, 0, l>, l1>␈↓
␈↓ ↓H␈↓            ␈↓↓* comcond[␈↓αd␈↓↓␈α∧u, m, l, vpr]]␈↓



␈↓ ↓H␈↓        ␈↓↓combool␈↓␈α⊂compiles␈α∂code␈α⊂for␈α∂a␈α⊂single␈α∂propositional␈α⊂expression.␈α∂ That␈α⊂is,␈α∂the␈α⊂code␈α∂generated
␈↓ ↓H␈↓evaluates␈αthe␈αexpression␈αand␈αbranches␈αsomewhere,␈αaccording␈αto␈αwhether␈αits␈αvalue␈αis␈αtrue␈αor␈αfalse.
␈↓ ↓H␈↓␈↓↓p␈↓␈αis␈αthe␈αpropositional␈αexpression.␈α ␈↓↓l␈↓␈αis␈αa␈αlabel␈αwhich␈αrepresents␈αthe␈αbranch␈αpoint.␈α ␈↓↓flg␈↓␈αis␈αa␈αflag.␈α If
␈↓ ↓H␈↓␈↓↓flg␈↓␈α
is␈α
␈↓¬NIL␈↓,␈αcode␈α
is␈α
to␈αfall␈α
thru␈α
on␈αnon-␈↓¬NIL␈↓␈α
result␈α
and␈αbranch␈α
to␈α
␈↓↓l␈↓␈αon␈α
␈↓¬NIL␈↓␈α
result.␈α If␈α
␈↓↓flg␈↓␈α
is␈αnon-␈↓¬NIL␈↓,
␈↓ ↓H␈↓code is to fall thru on ␈↓¬NIL␈↓ result and branch to ␈↓↓l␈↓ on non-␈↓¬NIL␈↓ result.


␈↓ ↓H␈↓        ␈↓↓combool[p, m, l, flg, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεp ␈↓αthen␈↓↓ ␈↓                                                       ~simple variable
␈↓ ↓H␈↓            ␈↓↓[compexp[p, m, vpr]␈↓
␈↓ ↓H␈↓             ␈↓↓* <<␈↓αif␈↓↓ flg ␈↓αthen␈↓↓ ␈↓¬JUMPN␈↓↓ ␈↓αelse␈↓↓ ␈↓¬JUMPE␈↓↓, 1, l>>]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧p = ␈↓¬AND␈↓↓ ␈↓αthen␈↓↓ ␈↓                                         ~conjunction
␈↓ ↓H␈↓            ␈↓↓[␈↓αif␈↓↓ ¬flg ␈↓αthen␈↓↓ compandor[␈↓αd␈↓↓␈α∧p, m, l, ␈↓¬NIL␈↓↓, vpr]␈↓
␈↓ ↓H␈↓             ␈↓↓␈↓αelse␈↓↓ {gensym[]}[λl1: ␈↓
␈↓ ↓H␈↓               ␈↓↓compandor[␈↓αd␈↓↓␈α∧p, m, l1, ␈↓¬NIL␈↓↓, vpr]␈↓
␈↓ ↓H␈↓               ␈↓↓* <<␈↓¬JRST␈↓↓, 0, l>>␈↓
␈↓ ↓H␈↓               ␈↓↓* <l1>]]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧p = ␈↓¬OR␈↓↓ ␈↓αthen␈↓↓ ␈↓                                          ~disjunction
␈↓ ↓H␈↓            ␈↓↓[␈↓αif␈↓↓ flg ␈↓αthen␈↓↓ compandor[␈↓αd␈↓↓␈α∧p, m, l, ␈↓¬T␈↓↓, vpr]␈↓
␈↓ ↓H␈↓             ␈↓↓␈↓αelse␈↓↓ {gensym[]}[λl1: ␈↓
␈↓ ↓H␈↓               ␈↓↓compandor[␈↓αd␈↓↓␈α∧p, m, l1, ␈↓¬T␈↓↓, vpr] * <<␈↓¬JRST␈↓↓, 0, l>> * <l1>]]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧p = ␈↓¬NOT␈↓↓ ␈↓αthen␈↓↓ combool[␈↓αad␈↓↓␈α∧p, m, l, ¬flg, vpr]␈↓                  ~negation
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ compexp[p, m, vpr]␈↓                                               ~other expression
␈↓ ↓H␈↓                ␈↓↓* <<␈↓αif␈↓↓ flg ␈↓αthen␈↓↓ ␈↓¬JUMPN␈↓↓ ␈↓αelse␈↓↓ ␈↓¬JUMPE␈↓↓, 1, l>>␈↓



␈↓ ↓H␈↓        ␈↓↓compandor␈↓␈α
compiles␈αcode␈α
for␈α
lists␈αof␈α
predicates␈α
connected␈αconjunctively␈α
or␈α
disjunctively.␈α ␈↓↓u␈↓
␈↓ ↓H␈↓is␈α
a␈αlist␈α
of␈α
predicates.␈α ␈↓↓l␈↓␈α
is␈αa␈α
label.␈α
 ␈↓↓flg␈↓␈αis␈α
a␈α
flag.␈α If␈α
␈↓↓flg␈↓␈αis␈α
␈↓¬NIL␈↓,␈α
we␈αare␈α
to␈α
fall␈αthru␈α
on␈αnon-␈↓¬NIL␈↓␈α
results
␈↓ ↓H␈↓and␈αbranch␈αto␈α␈↓↓l␈↓␈αon␈α␈↓¬NIL␈↓␈αresults␈α(␈↓¬AND␈α␈↓case).␈α If␈α␈↓↓flg␈↓␈αis␈αnon-␈↓¬NIL␈↓,␈αwe␈αare␈αto␈αfall␈αthru␈αon␈α␈↓¬NIL␈↓␈αresults␈αand
␈↓ ↓H␈↓branch to ␈↓↓l␈↓ on non-␈↓¬NIL␈↓ results (␈↓¬OR ␈↓case).


␈↓ ↓H␈↓        ␈↓↓compandor[u, m, l, flg, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ combool[␈↓αa␈↓↓␈α∧u, m, l, flg, vpr]␈↓
␈↓ ↓H␈↓                ␈↓↓* compandor[␈↓αd␈↓↓␈α∧u, m, l, flg, vpr]␈↓
␈↓ ↓H␈↓␈↓ ¬cCHAPTER IV␈↓ *81


␈↓ ↓H␈↓6.  ␈↓αLCOM4.␈↓



␈↓ ↓H␈↓        The␈α∞following␈α∞is␈α∞a␈α∂listing␈α∞in␈α∞external␈α∞notation␈α∞of␈α∂the␈α∞MACLISP␈α∞version␈α∞of␈α∂the␈α∞compiler
␈↓ ↓H␈↓LCOM4.␈α∞  A␈α∞listing␈α∞in␈α∞internal␈α∞notation␈α∞can␈α
be␈α∞found␈α∞in␈α∞Appendix␈α∞IV.␈α∞ Comments␈α∞are␈α
added
␈↓ ↓H␈↓where␈αthis␈αcompiler␈αdiffers␈αfrom␈αLCOM0.␈α The␈αmain␈αdifference␈αhas␈αto␈αdo␈αwith␈αthe␈αclassification
␈↓ ↓H␈↓of␈α
expressions␈α
into␈α
five␈α∞classes␈α
that␈α
can␈α
be␈α
compiled␈α∞differently␈α
for␈α
greater␈α
efficiency.␈α∞ The␈α
five
␈↓ ↓H␈↓classes are defined as follows:

␈↓ ↓H␈↓        0.      The constants ␈↓¬NIL␈↓, ␈↓¬T␈↓, and numbers.
␈↓ ↓H␈↓        1.      Variables -- any atom not considered a constant.
␈↓ ↓H␈↓        2.      Quoted S-expressions -- non-atomic constants.
␈↓ ↓H␈↓        3.      ␈↓↓car␈↓ - ␈↓↓cdr␈↓ chains applied to a variable.
␈↓ ↓H␈↓        4.      All others.



␈↓ ↓H␈↓        FEXPR:
␈↓ ↓H␈↓        ␈↓↓compl file ← ␈↓
␈↓ ↓H␈↓          ␈↓↓[uwrite[], ␈↓
␈↓ ↓H␈↓           ␈↓↓apply[␈↓¬EREAD␈↓↓, file], ␈↓
␈↓ ↓H␈↓           ␈↓↓select-disk-input[␈↓
␈↓ ↓H␈↓             ␈↓↓read-until-eof[with  z  do␈↓
␈↓ ↓H␈↓               ␈↓↓␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧z = ␈↓¬DEFUN␈↓↓ ∨ [␈↓αa␈↓↓␈α∧z = ␈↓¬DEFPROP␈↓↓ ∧ ␈↓αaddd␈↓↓␈α∧z = ␈↓¬EXPR␈↓↓] ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓                 ␈↓↓[␈↓αprog␈↓↓ [prog]␈↓
␈↓ ↓H␈↓                       ␈↓↓prog␈↓
␈↓ ↓H␈↓                        ␈↓↓← [␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧z = ␈↓¬DEFUN␈↓↓ ␈↓αthen␈↓↓ comp[␈↓αad␈↓↓␈α∧z, ␈↓αadd␈↓↓␈α∧z, ␈↓αaddd␈↓↓␈α∧z]␈↓
␈↓ ↓H␈↓                           ␈↓↓␈↓αelse␈↓↓ comp[␈↓αad␈↓↓␈α∧z, ␈↓αad␈↓↓␈α∧␈↓αadd␈↓↓␈α∧z, ␈↓αadd␈↓↓␈α∧␈↓αadd␈↓↓␈α∧z]]␈↓
␈↓ ↓H␈↓                       ␈↓↓unselect-tty ␈↓
␈↓ ↓H␈↓                         ␈↓↓select-disk-output mapc[print, prog]␈↓
␈↓ ↓H␈↓                       ␈↓↓print <␈↓αad␈↓↓␈α∧z, length prog>]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ unselect-tty select-disk-output print z], ␈↓
␈↓ ↓H␈↓             ␈↓↓apply[␈↓¬UFILE␈↓↓, <␈↓αa␈↓↓␈α∧file, ␈↓¬LAP␈↓↓>], ␈↓
␈↓ ↓H␈↓             ␈↓↓␈↓¬ENDCOMP␈↓↓]]␈↓


␈↓ ↓H␈↓        Instead␈α∞of␈α∂␈↓↓append␈↓ing␈α∞the␈α∂instructions␈α∞into␈α∂a␈α∞list␈α∂like␈α∞␈↓↓compexp␈↓␈α∂of␈α∞LCOM0␈α∂does,␈α∞LCOM4
␈↓ ↓H␈↓␈↓↓cons␈↓es␈αthem␈αinto␈αa␈α
tree␈αform␈αand␈αflattens␈αthe␈α
final␈αversion␈αinto␈αa␈αlist.␈α
 In␈αorder␈αthat␈αthe␈α
items␈αof
␈↓ ↓H␈↓the␈α
tree␈αform␈α
all␈α
have␈αthe␈α
structure␈α
of␈αa␈α
list␈αof␈α
atoms,␈α
labels␈αand␈α
the␈α
end␈αmark␈α
␈↓¬NIL␈↓␈α
are␈αput␈α
in␈αa␈α
list
␈↓ ↓H␈↓flagged␈αby␈α␈↓¬LABEL␈α
␈↓and␈αextracted␈αby␈α␈↓↓flat.␈↓␈α
 The␈αhope␈αwas␈αto␈α
make␈αthe␈αcompiler␈αfaster␈α
by␈αomitting
␈↓ ↓H␈↓all the calls to ␈↓↓append␈↓ but it does not seem to have made a lot of difference.


␈↓ ↓H␈↓        ␈↓↓comp[fn, vars, exp] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓{prup[vars, 1], length vars}[λvpr, n: ␈↓
␈↓ ↓H␈↓            ␈↓↓flat[<<<␈↓¬LAP␈↓↓, fn, ␈↓¬SUBR␈↓↓>>, ␈↓
␈↓ ↓H␈↓                  ␈↓↓mkpush[n, 1], ␈↓
␈↓ ↓H␈↓82␈↓ ¬cCHAPTER IV␈↓ H


␈↓ ↓H␈↓                  ␈↓↓compexp[exp, -n, vpr], ␈↓
␈↓ ↓H␈↓                  ␈↓↓substack n, ␈↓
␈↓ ↓H␈↓                  ␈↓↓␈↓¬((POPJ P) (LABEL NIL))␈↓↓>, ␈↓
␈↓ ↓H␈↓                 ␈↓↓␈↓¬NIL␈↓↓]]␈↓


␈↓ ↓H␈↓        ␈↓↓flat[u, s] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ s␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧␈↓αa␈↓↓␈α∧u ␈↓αthen␈↓↓ flat[␈↓αd␈↓↓␈α∧u, s]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧u = ␈↓¬LABEL␈↓↓ ␈↓αthen␈↓↓ ␈↓αad␈↓↓␈α∧u . s␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧u ␈↓αthen␈↓↓ u . s␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ flat[␈↓αa␈↓↓␈α∧u, flat[␈↓αd␈↓↓␈α∧u, s]]␈↓



␈↓ ↓H␈↓        ␈↓↓substack␈↓␈αcreates␈αcode␈αto␈αmove␈αdown␈αthe␈αstack,␈αbut␈αcreates␈αno␈αcode␈αfor␈αthe␈αcase␈α␈↓↓n␈↓␈α=␈α0␈αwhich
␈↓ ↓H␈↓is a no-op.


␈↓ ↓H␈↓        ␈↓↓substack n ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ n = 0 ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ <<␈↓¬SUB␈↓↓, ␈↓¬P␈↓↓, <␈↓¬%␈↓↓, 0, 0, n, n>>>␈↓



␈↓ ↓H␈↓        ␈↓↓prup[vars, n] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧vars ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ [␈↓αa␈↓↓␈α∧vars . n] . prup[␈↓αd␈↓↓␈α∧vars, add1 n]␈↓



␈↓ ↓H␈↓        ␈↓↓mkpush[n, m] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ n < m ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ <␈↓¬PUSH␈↓↓, ␈↓¬P␈↓↓, m> . mkpush[n, add1 m]␈↓



␈↓ ↓H␈↓        ␈↓↓compexp[exp, m, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧exp ␈↓αthen␈↓↓ ␈↓¬((MOVEI 1 0))␈↓↓␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ exp = ␈↓¬T␈↓↓ ∨ numberp exp ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<<␈↓¬MOVEI␈↓↓, 1, <␈↓¬QUOTE␈↓↓, exp>>>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεexp ␈↓αthen␈↓↓ <<␈↓¬MOVE␈↓↓, 1, m + ␈↓αd␈↓↓␈α∧assoc[exp, vpr], ␈↓¬P␈↓↓>>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧exp = ␈↓¬CAR␈↓↓ ␈↓αthen␈↓↓ ␈↓                                       ~compute ␈↓↓car␈↓ directly
␈↓ ↓H␈↓            ␈↓↓[␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αad␈↓↓␈α∧exp ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓              ␈↓↓<<␈↓¬HLRZ␈↓↓, 1, ␈↓¬@␈↓↓, m + ␈↓αd␈↓↓␈α∧assoc[␈↓αad␈↓↓␈α∧exp, vpr], ␈↓¬P␈↓↓>>␈↓
␈↓ ↓H␈↓             ␈↓↓␈↓αelse␈↓↓ <compexp[␈↓αad␈↓↓␈α∧exp, m, vpr], ␈↓¬((HLRZ 1 @ 1))␈↓↓>]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧exp = ␈↓¬CDR␈↓↓ ␈↓αthen␈↓↓ ␈↓                                       ~compute ␈↓↓cdr␈↓ directly
␈↓ ↓H␈↓            ␈↓↓[␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αad␈↓↓␈α∧exp ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓              ␈↓↓<<␈↓¬HRRZ␈↓↓, 1, ␈↓¬@␈↓↓, m + ␈↓αd␈↓↓␈α∧assoc[␈↓αad␈↓↓␈α∧exp, vpr], ␈↓¬P␈↓↓>>␈↓
␈↓ ↓H␈↓             ␈↓↓␈↓αelse␈↓↓ <compexp[␈↓αad␈↓↓␈α∧exp, m, vpr], ␈↓¬((HRRZ 1 @ 1))␈↓↓>]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧exp = ␈↓¬AND␈↓↓ ∨ ␈↓αa␈↓↓␈α∧exp = ␈↓¬OR␈↓↓ ∨ ␈↓αa␈↓↓␈α∧exp = ␈↓¬NOT␈↓↓ ∨ ␈↓αa␈↓↓␈α∧exp = ␈↓¬EQ␈↓↓␈↓
␈↓ ↓H␈↓␈↓ ¬cCHAPTER IV␈↓ *83


␈↓ ↓H␈↓            ␈↓↓␈↓αthen␈↓↓ {gensym[], gensym[]}[λl1, l2: ␈↓
␈↓ ↓H␈↓              ␈↓↓<combool[exp, m, l1, ␈↓¬NIL␈↓↓, vpr], ␈↓
␈↓ ↓H␈↓               ␈↓↓<␈↓¬(MOVEI 1 (QUOTE T))␈↓↓, ␈↓
␈↓ ↓H␈↓                ␈↓↓<␈↓¬JRST␈↓↓, 0, l2>, ␈↓
␈↓ ↓H␈↓                ␈↓↓<␈↓¬LABEL␈↓↓, l1>, ␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓¬(MOVEI 1 0)␈↓↓, ␈↓
␈↓ ↓H␈↓                ␈↓↓<␈↓¬LABEL␈↓↓, l2>>>]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧exp = ␈↓¬COND␈↓↓ ␈↓αthen␈↓↓ comcond[␈↓αd␈↓↓␈α∧exp, m, gensym[], vpr]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧exp = ␈↓¬QUOTE␈↓↓ ␈↓αthen␈↓↓ <<␈↓¬MOVEI␈↓↓, 1, exp>>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧exp ␈↓αthen␈↓↓ ␈↓                                            ~uses improved arg evaluation
␈↓ ↓H␈↓            ␈↓↓<complisa[␈↓αd␈↓↓␈α∧exp, m, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓<<␈↓¬CALL␈↓↓, length ␈↓αd␈↓↓␈α∧exp, <␈↓¬QUOTE␈↓↓, ␈↓αa␈↓↓␈α∧exp>>>>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧exp = ␈↓¬LAMBDA␈↓↓ ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓{length ␈↓αd␈↓↓␈α∧exp}[λn: ␈↓
␈↓ ↓H␈↓              ␈↓↓<stackup[␈↓αd␈↓↓␈α∧exp, m, vpr], ␈↓
␈↓ ↓H␈↓               ␈↓↓compexp[␈↓αadda␈↓↓␈α∧exp, m - n, prup[␈↓αada␈↓↓␈α∧exp, 1 - m] * vpr], ␈↓
␈↓ ↓H␈↓               ␈↓↓substack n>]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓¬NIL␈↓↓␈↓




␈↓ ↓H␈↓        ␈↓↓stackup[u, m, vpr] ← ␈↓                             ~␈↓↓stackup␈↓ is the same as ␈↓↓complis␈↓ of LCOM0.
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ <compexp[␈↓αa␈↓↓␈α∧u, m, vpr], ␈↓
␈↓ ↓H␈↓                 ␈↓↓␈↓¬((PUSH P 1))␈↓↓, ␈↓
␈↓ ↓H␈↓                 ␈↓↓stackup[␈↓αd␈↓↓␈α∧u, sub1 m, vpr]>␈↓




␈↓ ↓H␈↓        ␈↓↓ccchain␈↓ test whether an expression is a ␈↓↓car␈↓ - ␈↓↓cdr␈↓ chain applied to a variable.


␈↓ ↓H␈↓        ␈↓↓ccchain exp ← ␈↓
␈↓ ↓H␈↓          ␈↓↓[␈↓αa␈↓↓␈α∧exp = ␈↓¬CAR␈↓↓ ∨ ␈↓αa␈↓↓␈α∧exp = ␈↓¬CDR␈↓↓] ∧ [␈↓αat␈↓↓␈αε␈↓αad␈↓↓␈α∧exp ∨ ccchain ␈↓αad␈↓↓␈α∧exp]␈↓



␈↓ ↓H␈↓        ␈↓↓compc␈↓␈α⊂generates␈α∂code␈α⊂(in␈α∂reverse␈α⊂order)␈α⊂to␈α∂load␈α⊂the␈α∂value␈α⊂of␈α⊂a␈α∂␈↓↓car␈↓␈α⊂-␈α∂␈↓↓cdr␈↓␈α⊂chain␈α⊂into␈α∂the
␈↓ ↓H␈↓accumulator designated by ␈↓↓n2.␈↓


␈↓ ↓H␈↓        ␈↓↓compc[exp, n2, m, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεexp ␈↓αthen␈↓↓ error ␈↓¬COMPC␈↓↓␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧exp = ␈↓¬CAR␈↓↓ ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓[␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αad␈↓↓␈α∧exp ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓              ␈↓↓<<␈↓¬HLRZ␈↓↓, n2, ␈↓¬@␈↓↓, m + ␈↓αd␈↓↓␈α∧assoc[␈↓αad␈↓↓␈α∧exp, vpr], ␈↓¬P␈↓↓>>␈↓
␈↓ ↓H␈↓84␈↓ ¬cCHAPTER IV␈↓ H


␈↓ ↓H␈↓             ␈↓↓␈↓αelse␈↓↓ <␈↓¬HLRZ␈↓↓, n2, ␈↓¬@␈↓↓, n2> . compc[␈↓αad␈↓↓␈α∧exp, n2, m, vpr]]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αad␈↓↓␈α∧exp ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<<␈↓¬HRRZ␈↓↓, ␈↓¬@␈↓↓, n2, m + ␈↓αd␈↓↓␈α∧assoc[␈↓αad␈↓↓␈α∧exp, vpr], ␈↓¬P␈↓↓>>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ <␈↓¬HRRZ␈↓↓, n2, ␈↓¬@␈↓↓, n2> . compc[␈↓αad␈↓↓␈α∧exp, n2, m, vpr]␈↓




␈↓ ↓H␈↓        ␈↓↓comcond␈↓␈αis␈αessentially␈αthe␈αsame␈αas␈αin␈αLCOM0.␈α It␈αoptimizes␈αby␈αconsidering␈αthe␈αspecial␈αcases
␈↓ ↓H␈↓where␈αthe␈αnext␈α
clause␈αin␈αthe␈αlist␈α
of␈αarguments␈αto␈α
␈↓¬COND␈αis␈α␈↓of␈αthe␈α
form␈α␈↓¬((NULL ␈↓↓e␈↓¬) NIL)␈↓␈α or␈α
␈↓¬(T ␈↓↓e␈↓¬)␈↓␈α for
␈↓ ↓H␈↓some expression ␈↓↓e.␈↓


␈↓ ↓H␈↓        ␈↓↓comcond[u, m, l, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ <<␈↓¬LABEL␈↓↓, l>>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ¬␈↓αat␈↓↓␈αε␈↓αaa␈↓↓␈α∧u ∧ ␈↓αaaa␈↓↓␈α∧u = ␈↓¬NULL␈↓↓ ∧ ␈↓αn␈↓↓␈α∧␈↓αada␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<compexp[␈↓αadaa␈↓↓␈α∧u, m, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓<<␈↓¬JUMPE␈↓↓, 1, l>>, ␈↓
␈↓ ↓H␈↓             ␈↓↓comcond[␈↓αd␈↓↓␈α∧u, m, l, vpr]>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧u = ␈↓¬T␈↓↓ ␈↓αthen␈↓↓ <compexp[␈↓αada␈↓↓␈α∧u, m, vpr], <<␈↓¬LABEL␈↓↓, l>>>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ {gensym[]}[λl1: ␈↓
␈↓ ↓H␈↓            ␈↓↓<combool[␈↓αaa␈↓↓␈α∧u, m, l1, ␈↓¬NIL␈↓↓, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓compexp[␈↓αada␈↓↓␈α∧u, m, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓<<␈↓¬JRST␈↓↓, 0, l>, <␈↓¬LABEL␈↓↓, l1>>, ␈↓
␈↓ ↓H␈↓             ␈↓↓comcond[␈↓αd␈↓↓␈α∧u, m, l, vpr]>]␈↓



␈↓ ↓H␈↓        ␈↓↓complisa␈↓␈αclassifies␈αthe␈αexpressions␈αon␈αthe␈αargument␈αlist␈α␈↓↓u,␈↓␈αcalls␈α␈↓↓complis␈↓␈αto␈αgenerate␈αcode␈αfor
␈↓ ↓H␈↓those␈α∞arguments␈α∂which␈α∞must␈α∂be␈α∞computed␈α∂and␈α∞stored␈α∂on␈α∞the␈α∂stack,␈α∞␈↓↓loadac␈↓␈α∂to␈α∞generate␈α∂code␈α∞for
␈↓ ↓H␈↓loading the accumulators and ␈↓↓substack␈↓ to generate code to restore the stack.


␈↓ ↓H␈↓        ␈↓↓complisa[u, m, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓{classify u}[λz: ␈↓
␈↓ ↓H␈↓            ␈↓↓<complis[z, m, 1, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓loadac[z, 1 - ccount z, 1, m - ccount z, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓substack ccount z>]␈↓



␈↓ ↓H␈↓        ␈↓↓ccount␈↓␈αof␈α
a␈αlist␈α
of␈αclassified␈αexpressions␈α
is␈αthe␈α
number␈αof␈αexpressions␈α
on␈αthe␈α
list␈αof␈α
class␈α4.
␈↓ ↓H␈↓That is the number of values that will have to be stacked when evaluating ␈↓↓z␈↓ as an argument list.


␈↓ ↓H␈↓        ␈↓↓ccount z ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧z ␈↓αthen␈↓↓ 0␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧z = 4 ␈↓αthen␈↓↓ add1 ccount ␈↓αd␈↓↓␈α∧z␈↓
␈↓ ↓H␈↓␈↓ ¬cCHAPTER IV␈↓ *85


␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ccount ␈↓αd␈↓↓␈α∧z␈↓



␈↓ ↓H␈↓        ␈↓↓loadac␈↓␈αcompiles␈αcode␈αto␈αload␈αaccumulators␈α␈↓↓n2␈↓␈αand␈αup␈αwith␈αthe␈αvalues␈αof␈αthe␈αexpressions␈αon
␈↓ ↓H␈↓the␈α⊃list␈α∩␈↓↓z␈↓␈α⊃of␈α∩classified␈α⊃expressions.␈α∩ ␈↓↓m2␈↓␈α⊃is␈α∩the␈α⊃stack␈α⊃offset␈α∩for␈α⊃the␈α∩value␈α⊃of␈α∩the␈α⊃next␈α∩class␈α⊃4
␈↓ ↓H␈↓expression on the list.


␈↓ ↓H␈↓        ␈↓↓loadac[z, m2, n2, m, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧z ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧z = 1 ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<␈↓¬MOVE␈↓↓, n2, m + ␈↓αd␈↓↓␈α∧assoc[␈↓αda␈↓↓␈α∧z, vpr], ␈↓¬P␈↓↓>␈↓
␈↓ ↓H␈↓            ␈↓↓. loadac[␈↓αd␈↓↓␈α∧z, m2, add1 n2, m, vpr]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧z = 0 ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<␈↓¬MOVEI␈↓↓, n2, <␈↓¬QUOTE␈↓↓, ␈↓αda␈↓↓␈α∧z>>␈↓
␈↓ ↓H␈↓            ␈↓↓. loadac[␈↓αd␈↓↓␈α∧z, m2, add1 n2, m, vpr]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧z = 2 ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<␈↓¬MOVEI␈↓↓, n2, ␈↓αda␈↓↓␈α∧z> . loadac[␈↓αd␈↓↓␈α∧z, m2, add1 n2, m, vpr]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧z = 3 ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<reverse compc[␈↓αda␈↓↓␈α∧z, n2, m, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓loadac[␈↓αd␈↓↓␈α∧z, m2, add1 n2, m, vpr]>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧z = 5 ␈↓αthen␈↓↓ loadac[␈↓αd␈↓↓␈α∧z, 1, add1 n2, m, vpr]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ <␈↓¬MOVE␈↓↓, n2, m2, ␈↓¬P␈↓↓>␈↓
␈↓ ↓H␈↓                ␈↓↓. loadac[␈↓αd␈↓↓␈α∧z, add1 m2, add1 n2, m, vpr]␈↓



␈↓ ↓H␈↓        ␈↓↓complis␈↓␈αgenerates␈αcode␈αto␈αstack␈αthe␈αvalues␈αof␈αthe␈αclass␈α4␈αexpressions␈αon␈αthe␈αlist␈αof␈αclassified
␈↓ ↓H␈↓expressions␈α␈↓↓z.␈↓␈α ␈↓↓k␈↓␈αis␈αthe␈αaccumulator␈αwhere␈αthe␈αnext␈αvalue␈αshould␈αgo.␈α The␈αlast␈αclass 4␈αexpression
␈↓ ↓H␈↓is␈α∞marked␈α∞class 5.␈α∞ When␈α∞this␈α∞is␈α∞evaluated␈α∞it␈α∞is␈α∞loaded␈α∞directly␈α∞rather␈α∞than␈α∞being␈α∞stacked.␈α∞ If␈α
a
␈↓ ↓H␈↓class 5 expression is encountered, ␈↓↓complis␈↓ can quit as it has no more work.


␈↓ ↓H␈↓        ␈↓↓complis[z, m, k, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧z ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧z = 4 ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<compexp[␈↓αda␈↓↓␈α∧z, m, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓␈↓¬((PUSH P 1))␈↓↓, ␈↓
␈↓ ↓H␈↓             ␈↓↓complis[␈↓αd␈↓↓␈α∧z, sub1 m, add1 k, vpr]>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧z = 5 ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<compexp[␈↓αda␈↓↓␈α∧z, m, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓␈↓αif␈↓↓ k = 1 ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓ ␈↓αelse␈↓↓ <<␈↓¬MOVE␈↓↓, k, 1>>>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ complis[␈↓αd␈↓↓␈α∧z, m, add1 k, vpr]␈↓
␈↓ ↓H␈↓86␈↓ ¬cCHAPTER IV␈↓ H


␈↓ ↓H␈↓        ␈↓↓classify␈↓␈αtakes␈αa␈αlist␈αof␈αexpressions␈αand␈αreturns␈αa␈αcorresponding␈αlist␈αof␈α
classified␈αexpressions
␈↓ ↓H␈↓of␈αthe␈αform␈α[␈↓↓n␈↓␈α
.␈α␈↓↓e]␈↓␈αwhere␈α␈↓↓n␈↓␈α
is␈αthe␈αclass␈αof␈α␈↓↓e␈↓␈α
according␈αto␈αthe␈αrules␈α
given␈αat␈αthe␈αbeginning␈α
of␈αthe
␈↓ ↓H␈↓listing.  The last class 4 expression on the list is numbered 5.


␈↓ ↓H␈↓        ␈↓↓classify u ← class2[class1[u, ␈↓¬NIL␈↓↓], ␈↓¬NIL␈↓↓, ␈↓¬T␈↓↓]␈↓


␈↓ ↓H␈↓        ␈↓↓class1[u, v] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ v␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓[␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧u = ␈↓¬NIL␈↓↓ ∨ ␈↓αa␈↓↓␈α∧u = ␈↓¬T␈↓↓ ∨ numberp ␈↓αa␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓              ␈↓↓class1[␈↓αd␈↓↓␈α∧u, [0 . ␈↓αa␈↓↓␈α∧u] . v]␈↓
␈↓ ↓H␈↓             ␈↓↓␈↓αelse␈↓↓ class1[␈↓αd␈↓↓␈α∧u, [1 . ␈↓αa␈↓↓␈α∧u] . v]]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧u = ␈↓¬QUOTE␈↓↓ ␈↓αthen␈↓↓ class1[␈↓αd␈↓↓␈α∧u, [2 . ␈↓αa␈↓↓␈α∧u] . v]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ccchain ␈↓αa␈↓↓␈α∧u ␈↓αthen␈↓↓ class1[␈↓αd␈↓↓␈α∧u, [3 . ␈↓αa␈↓↓␈α∧u] . v]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ class1[␈↓αd␈↓↓␈α∧u, [4 . ␈↓αa␈↓↓␈α∧u] . v]␈↓


␈↓ ↓H␈↓        ␈↓↓class2[u, v, flg] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ v␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ flg ∧ ␈↓αaa␈↓↓␈α∧u = 4 ␈↓αthen␈↓↓ class2[␈↓αd␈↓↓␈α∧u, [5 . ␈↓αda␈↓↓␈α∧u] . v, ␈↓¬NIL␈↓↓]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ class2[␈↓αd␈↓↓␈α∧u, ␈↓αa␈↓↓␈α∧u . v, flg]␈↓


␈↓ ↓H␈↓        ␈↓↓mkjrst l ← <<␈↓¬JRST␈↓↓, 0, l>>␈↓



␈↓ ↓H␈↓        ␈↓↓combool␈↓␈α
is␈α
essentially␈αthe␈α
same␈α
as␈α
in␈αLCOM0␈α
except␈α
it␈α
treats␈αadditional␈α
special␈α
cases␈αwhere␈α
␈↓↓p␈↓
␈↓ ↓H␈↓is␈αof␈αthe␈αform␈α␈↓¬T␈↓,␈α␈↓¬(EQ␈α␈↓↓e1␈↓¬␈α␈↓↓e2␈↓¬)␈↓,␈α
or␈α␈↓¬(NULL␈α␈↓↓e␈↓¬)␈↓.␈α It␈αalso␈αhandles␈αthe␈αjumping␈αsomewhat␈α
differently␈αusing
␈↓ ↓H␈↓two versions of ␈↓↓compandor.␈↓


␈↓ ↓H␈↓        ␈↓↓combool[p, m, l, flg, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ p = ␈↓¬T␈↓↓ ␈↓αthen␈↓↓ [␈↓αif␈↓↓ flg ␈↓αthen␈↓↓ mkjrst l ␈↓αelse␈↓↓ ␈↓¬NIL␈↓↓]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεp ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<compexp[p, m, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓<<␈↓αif␈↓↓ flg ␈↓αthen␈↓↓ ␈↓¬JUMPN␈↓↓ ␈↓αelse␈↓↓ ␈↓¬JUMPE␈↓↓, 1, l>>>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧p = ␈↓¬EQ␈↓↓ ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<complisa[␈↓αd␈↓↓␈α∧p, m, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓␈↓αif␈↓↓ flg ␈↓αthen␈↓↓ ␈↓¬((CAMN 1 2))␈↓↓ ␈↓αelse␈↓↓ ␈↓¬((CAME 1 2))␈↓↓, ␈↓
␈↓ ↓H␈↓             ␈↓↓mkjrst l>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧p = ␈↓¬AND␈↓↓ ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓[␈↓αif␈↓↓ ¬flg ␈↓αthen␈↓↓ compandor[␈↓αd␈↓↓␈α∧p, m, l, ␈↓¬NIL␈↓↓, vpr]␈↓
␈↓ ↓H␈↓             ␈↓↓␈↓αelse␈↓↓ {gensym[]}[λl1: ␈↓
␈↓ ↓H␈↓               ␈↓↓<compandor1[␈↓αd␈↓↓␈α∧p, m, l1, l, ␈↓¬NIL␈↓↓, vpr], <<␈↓¬LABEL␈↓↓, l1>>>]]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧p = ␈↓¬OR␈↓↓ ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓␈↓ ¬cCHAPTER IV␈↓ *87


␈↓ ↓H␈↓            ␈↓↓[␈↓αif␈↓↓ flg ␈↓αthen␈↓↓ compandor[␈↓αd␈↓↓␈α∧p, m, l, ␈↓¬T␈↓↓, vpr]␈↓
␈↓ ↓H␈↓             ␈↓↓␈↓αelse␈↓↓ {gensym[]}[λl1: ␈↓
␈↓ ↓H␈↓               ␈↓↓<compandor1[␈↓αd␈↓↓␈α∧p, m, l1, l, ␈↓¬T␈↓↓, vpr], <<␈↓¬LABEL␈↓↓, l1>>>]]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧p = ␈↓¬NOT␈↓↓ ␈↓αthen␈↓↓ combool[␈↓αad␈↓↓␈α∧p, m, l, ¬flg, vpr]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧p = ␈↓¬NULL␈↓↓ ␈↓αthen␈↓↓ ␈↓
␈↓ ↓H␈↓            ␈↓↓<compexp[␈↓αad␈↓↓␈α∧p, m, vpr], ␈↓
␈↓ ↓H␈↓             ␈↓↓<<␈↓αif␈↓↓ flg ␈↓αthen␈↓↓ ␈↓¬JUMPE␈↓↓ ␈↓αelse␈↓↓ ␈↓¬JUMPN␈↓↓, 1, l>>>␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ <compexp[p, m, vpr], ␈↓
␈↓ ↓H␈↓                 ␈↓↓<<␈↓αif␈↓↓ flg ␈↓αthen␈↓↓ ␈↓¬JUMPN␈↓↓ ␈↓αelse␈↓↓ ␈↓¬JUMPE␈↓↓, 1, l>>>␈↓


␈↓ ↓H␈↓        ␈↓↓compandor[u, m, l, flg, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ <combool[␈↓αa␈↓↓␈α∧u, m, l, flg, vpr], ␈↓
␈↓ ↓H␈↓                 ␈↓↓compandor[␈↓αd␈↓↓␈α∧u, m, l, flg, vpr]>␈↓


␈↓ ↓H␈↓        ␈↓↓compandor1[u, m, l, l2, flg, vpr] ← ␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ mkjrst l2␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧␈↓αd␈↓↓␈α∧u ␈↓αthen␈↓↓ combool[␈↓αa␈↓↓␈α∧u, m, l2, ¬flg, vpr]␈↓
␈↓ ↓H␈↓          ␈↓↓␈↓αelse␈↓↓ <combool[␈↓αa␈↓↓␈α∧u, m, l, flg, vpr], ␈↓
␈↓ ↓H␈↓                 ␈↓↓compandor1[␈↓αd␈↓↓␈α∧u, m, l, l2, flg, vpr]>␈↓
␈↓ ↓H␈↓88␈↓ εH␈↓ H


␈↓ ↓H␈↓α␈↓ εαChapter V

␈↓ ↓H␈↓α␈↓ ¬BCOMPUTABILITY




␈↓ ↓H␈↓1.  ␈↓αA universal LISP function.␈↓


␈↓ ↓H␈↓        Except␈αfor␈αspeed␈αand␈αmemory␈αsize␈αall␈αpresent␈αday␈αstored␈αprogram␈αcomputers␈αare␈αequivalent
␈↓ ↓H␈↓in␈αwhat␈αcomputations␈αthey␈αcan␈αdo.␈α A␈αprogram␈αwritten␈αfor␈αone␈αcomputer␈αcan␈αbe␈αtranslated␈αto␈αrun
␈↓ ↓H␈↓on␈αanother.␈α Indeed,␈αone␈αcan␈αwrite␈αa␈αsimulator␈αfor␈αone␈αcomputer␈αto␈αrun␈αon␈αanother.␈α To␈αput␈αit␈αin
␈↓ ↓H␈↓commercial␈α
terms,␈α
no␈α
computer␈α
manufacturer␈α
can␈α
advertise␈α
that␈α
his␈α
machine␈α
can␈α
do␈αcalculations
␈↓ ↓H␈↓impossible on the machine made by his competitors.

␈↓ ↓H␈↓        This␈αis␈αwell␈αknown␈αintuitively,␈αand␈αthe␈αfirst␈αmathematical␈αtheorem␈αof␈αthis␈αkind␈αwas␈αproved
␈↓ ↓H␈↓by␈αA.M.␈αTuring␈α(1936),␈αwho␈αdefined␈αa␈αprimitive␈αkind␈αof␈αcomputer␈αnow␈αcalled␈αa␈αTuring␈αmachine,
␈↓ ↓H␈↓and␈α⊃showed␈α⊃how␈α⊃to␈α⊃make␈α⊂a␈α⊃universal␈α⊃machine␈α⊃that␈α⊃could␈α⊂do␈α⊃any␈α⊃computation␈α⊃done␈α⊃by␈α⊂any
␈↓ ↓H␈↓Turing␈αmachine␈αwhen␈αgiven␈αa␈αdescription␈αof␈αthe␈αmachine␈αto␈αbe␈αsimulated␈αand␈αthe␈αinitial␈αtape␈αof
␈↓ ↓H␈↓the computation to be imitated.

␈↓ ↓H␈↓        In␈α∞LISP␈α∞the␈α∂function␈α∞␈↓↓eval,␈↓␈α∞defined␈α∞in␈α∂Chapter␈α∞IV,␈α∞ is␈α∞a␈α∂universal␈α∞LISP␈α∞function␈α∂in␈α∞the
␈↓ ↓H␈↓sense␈α
that␈α
any␈α
computation␈α
done␈αby␈α
any␈α
LISP␈α
function␈α
can␈α
be␈αdone␈α
by␈α
␈↓↓eval␈↓␈α
when␈α
␈↓↓eval␈↓␈α
is␈αgiven
␈↓ ↓H␈↓suitable arguments.

␈↓ ↓H␈↓        The␈α⊂way␈α⊂␈↓↓eval␈↓␈α⊂handles␈α⊂arguments␈α∂corresponds␈α⊂to␈α⊂the␈α⊂call-by-value␈α⊂method␈α⊂of␈α∂parameter
␈↓ ↓H␈↓passing␈αin␈αALGOL␈αand␈αsimilar␈αlanguages.␈α There␈αis␈αalso␈αa␈αform␈αof␈α␈↓↓eval␈↓␈αthat␈αcorresponds␈αto␈αcall-
␈↓ ↓H␈↓by-name.  Here it is:

␈↓ ↓H␈↓                ␈↓↓neval[e, a] ← ␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αif␈↓↓ ␈↓αat␈↓↓␈αεe ␈↓αthen␈↓↓␈↓
␈↓ ↓H␈↓                        ␈↓↓[␈↓αif␈↓↓ e = ␈↓¬T␈↓↓  ␈↓αthen␈↓↓ ␈↓¬T␈↓↓␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ e = ␈↓¬NIL␈↓↓ ␈↓αthen␈↓↓ ␈↓¬NIL␈↓↓␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ numberp e ␈↓αthen␈↓↓ e␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ neval[␈↓αad␈↓↓␈α∧assoc[e, a], ␈↓αdd␈↓↓␈α∧assoc[e, a]]]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αat␈↓↓␈αε␈↓αa␈↓↓␈α∧e ␈↓αthen␈↓↓␈↓
␈↓ ↓H␈↓                        ␈↓↓[␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬CAR ␈↓↓␈↓αthen␈↓↓ ␈↓αa␈↓↓␈α∧neval[␈↓αad␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬CDR ␈↓↓␈↓αthen␈↓↓ ␈↓αd␈↓↓␈α∧neval[␈↓αad␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬CONS ␈↓↓␈↓αthen␈↓↓ neval[␈↓αad␈↓↓␈α∧e, a] . neval[␈↓αadd␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬ATOM ␈↓↓␈↓αthen␈↓↓ ␈↓αat␈↓↓␈αεneval[␈↓αad␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬EQ ␈↓↓␈↓αthen␈↓↓ neval[␈↓αad␈↓↓␈α∧e, a] = neval[␈↓αadd␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬QUOTE ␈↓↓␈↓αthen␈↓↓ ␈↓αad␈↓↓␈α∧e␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬COND ␈↓↓␈↓αthen␈↓↓ nevcon[␈↓αd␈↓↓␈α∧e, a]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αa␈↓↓␈α∧e = ␈↓¬LIST ␈↓↓␈↓αthen␈↓↓ mapcar[␈↓αd␈↓↓␈α∧e, λx: neval[x, a]]␈↓
␈↓ ↓H␈↓                        ␈↓↓␈↓αelse␈↓↓ neval[␈↓αd␈↓↓␈α∧assoc[␈↓αa␈↓↓␈α∧e, a] . ␈↓αd␈↓↓␈α∧e, a]]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧e = ␈↓¬LAMBDA ␈↓↓␈↓αthen␈↓↓ neval[␈↓αadda␈↓↓␈α∧e, nprup[␈↓αada␈↓↓␈α∧e, ␈↓αd␈↓↓␈α∧e,  a]]␈↓
␈↓ ↓H␈↓                ␈↓↓␈↓αelse␈↓↓ ␈↓αif␈↓↓ ␈↓αaa␈↓↓␈α∧e = ␈↓¬LABEL ␈↓↓␈↓αthen␈↓↓ neval[␈↓αadda␈↓↓␈α∧e . ␈↓αd␈↓↓␈α∧e, [␈↓αada␈↓↓␈α∧e . ␈↓αa␈↓↓␈α∧e] . a]␈↓,
␈↓ ↓H␈↓␈↓ ¬hCHAPTER V␈↓ *89


␈↓ ↓H␈↓where the auxiliary function ␈↓↓nevcon␈↓ is given by

␈↓ ↓H␈↓␈↓ αv␈↓↓nevcon[u, a] ← ␈↓αif␈↓↓ neval[␈↓αaa␈↓↓␈α∧u, a] ␈↓αthen␈↓↓ neval[␈↓αada␈↓↓␈α∧u, a] ␈↓αelse␈↓↓ nevcon[␈↓αd␈↓↓␈α∧u, a]␈↓. 

␈↓ ↓H␈↓and ␈↓↓nprup␈↓ is

␈↓ ↓H␈↓␈↓ ββ␈↓↓nprup[u, v,a] ← ␈↓αif␈↓↓ ␈↓αn␈↓↓␈α∧u ␈↓αthen␈↓↓ a ␈↓αelse␈↓↓ [␈↓αa␈↓↓␈α∧u . [␈↓αa␈↓↓␈α∧v . a]] . nprup[␈↓αd␈↓↓␈α∧u, ␈↓αd␈↓↓␈α∧v,a]␈↓. 

␈↓ ↓H␈↓        The␈α
difference␈α
between␈α∞␈↓↓eval␈↓␈α
and␈α
␈↓↓neval␈↓␈α
is␈α∞only␈α
in␈α
two␈α
terms.␈α∞ ␈↓↓eval␈↓␈α
evaluates␈α
a␈α∞variable␈α
by
␈↓ ↓H␈↓looking␈αit␈αup␈αon␈αthe␈αassociation␈αlist␈αwhereas␈α
␈↓↓neval␈↓␈αlooks␈αit␈αup␈αon␈αthe␈αassociation␈αlist␈αand␈α
evaluates
␈↓ ↓H␈↓the␈αresult␈αin␈αthe␈αcontext␈αin␈αwhich␈αit␈αwas␈αput␈αon␈αthe␈αassociation␈αlist.␈α Correspondingly,␈αwhen␈αa␈αλ-
␈↓ ↓H␈↓expression␈α
is␈αencountered,␈α
␈↓↓eval␈↓␈α
forms␈αa␈α
new␈α
association␈αlist␈α
by␈α
pairing␈αthe␈α
values␈α
of␈αthe␈α
arguments
␈↓ ↓H␈↓with␈αthe␈α
variables␈αbound␈αby␈α
the␈αλ␈αand␈α
putting␈αthe␈αnew␈α
pairs␈αin␈αfront␈α
of␈αthe␈αold␈α
association␈αlist,
␈↓ ↓H␈↓whereas␈α
␈↓↓neval␈↓␈α
pairs␈α
the␈α
arguments␈α
themselves␈α
with␈αthe␈α
variables␈α
and␈α
puts␈α
them␈α
on␈α
the␈α
front␈αof
␈↓ ↓H␈↓the␈α
association␈αlist.␈α
 The␈α
function␈α␈↓↓neval␈↓␈α
also␈α
saves␈αthe␈α
current␈α
association␈αlist␈α
with␈α
each␈αvariable
␈↓ ↓H␈↓on␈αthe␈αassociation␈αlist,␈αso␈αthat␈αthe␈αvariables␈αcan␈αbe␈αevaluated␈αin␈αthe␈αcorrect␈αcontext.␈α In␈αmost␈αcases
␈↓ ↓H␈↓they␈α⊂give␈α∂the␈α⊂same␈α∂result␈α⊂with␈α∂the␈α⊂same␈α∂work,␈α⊂but␈α∂␈↓↓neval␈↓␈α⊂gives␈α∂a␈α⊂result␈α∂for␈α⊂some␈α⊂functions␈α∂of
␈↓ ↓H␈↓several␈αarguments␈αfor␈αwhich␈α␈↓↓eval␈↓␈αloops.␈α An␈αexample␈αis␈αobtained␈αby␈αevaluating␈α␈↓↓F[2,␈α1]␈↓␈αwhere␈α␈↓↓F␈↓
␈↓ ↓H␈↓is defined by

␈↓ ↓H␈↓␈↓ ∧
␈↓↓F[x, y] ← ␈↓αif␈↓↓ x=0 ␈↓αthen␈↓↓ 0 ␈↓αelse␈↓↓ F[x-1, F[y-2, x]]␈↓. 

␈↓ ↓H␈↓        Vuillemin␈α
(1973)␈α
showed␈α
that␈α
if␈α
a␈α
function␈α∞is␈α
␈↓↓strict,␈↓␈α
never␈α
has␈α
a␈α
defined␈α
value␈α∞unless␈α
all
␈↓ ↓H␈↓arguments have a defined value, then call-by-name and call-by-value always give the same result.


␈↓ ↓H␈↓α␈↓ ε
Exercises

␈↓ ↓H␈↓1.␈α⊂Write␈α⊃␈↓↓neval␈↓␈α⊂and␈α⊂the␈α⊃necessary␈α⊂auxiliary␈α⊃functions␈α⊂in␈α⊂list␈α⊃form,␈α⊂and␈α⊂try␈α⊃them␈α⊂out␈α⊃on␈α⊂some
␈↓ ↓H␈↓examples.



␈↓ ↓H␈↓2.  ␈↓αNon-computability.␈↓


␈↓ ↓H␈↓        Some␈α∞LISP␈α
calculations␈α∞run␈α∞on␈α
indefinitely.␈α∞ The␈α∞most␈α
trivial␈α∞case␈α∞occurs␈α
if␈α∞we␈α∞make␈α
the
␈↓ ↓H␈↓recursive definition

␈↓ ↓H␈↓␈↓ ¬#␈↓↓loop x ← loop x              ␈↓ 

␈↓ ↓H␈↓and␈α
attempt␈α
to␈α
compute␈α
␈↓↓loop[x]␈↓␈α
for␈α
any␈α
␈↓↓x␈↓␈α
whatsoever.␈α
 Don't␈α
dismiss␈α
this␈α
example␈α
just␈αbecause␈α
no-
␈↓ ↓H␈↓one␈αwould␈αwrite␈αsuch␈αan␈αobviously␈αuseless␈αfunction␈αdefinition.␈α There␈αis␈αa␈αsense␈αin␈αwhich␈αit␈αis␈α
the
␈↓ ↓H␈↓"zero"␈α∞of␈α∞a␈α
large␈α∞class␈α∞of␈α
non-terminating␈α∞function␈α∞definitions,␈α
and,␈α∞as␈α∞the␈α∞Romans␈α
experienced
␈↓ ↓H␈↓but never learned, leaving zero out of the number system is a mistake.

␈↓ ↓H␈↓        Nevertheless,␈αin␈αmost␈α
programming,␈αnon-terminating␈αcalculations␈αare␈α
the␈αresults␈αof␈αerrors␈α
in
␈↓ ↓H␈↓90␈↓ ¬hCHAPTER V␈↓ H


␈↓ ↓H␈↓defining␈αfunctions.␈α Therefore,␈αit␈αwould␈αbe␈αuseful␈αto␈αbe␈αable␈αto␈αtell␈αwhether␈αa␈αfunction␈αdefinition
␈↓ ↓H␈↓gives␈αa␈αresult␈α
for␈αall␈αarguments.␈α In␈α
fact,␈αit␈αwould␈αbe␈α
useful␈αto␈αbe␈αable␈α
to␈αtell␈αwhether␈α
a␈αfunction
␈↓ ↓H␈↓will terminate for a single argument.  Let us make this goal more precise.

␈↓ ↓H␈↓        Suppose␈α∞that␈α
␈↓↓f␈↓␈α∞is␈α∞a␈α
LISP␈α∞function␈α∞and␈α
␈↓↓a␈↓␈α∞is␈α∞an␈α
S-expression,␈α∞and␈α∞we␈α
would␈α∞like␈α∞to␈α
know
␈↓ ↓H␈↓whether␈α
the␈α
computation␈αof␈α
␈↓↓f[a]␈↓␈α
terminates.␈α
 Suppose␈α␈↓↓f␈↓␈α
is␈α
represented␈αby␈α
the␈α
S-expression␈α
␈↓↓f*␈↓␈αin
␈↓ ↓H␈↓internal␈α
notation.␈α
 Then␈α
the␈α
S-expression␈α
␈↓¬(␈↓↓f*␈↓¬␈α(QUOTE␈α
␈↓↓a␈↓¬))␈↓␈α
represents␈α
␈↓↓f[a].␈↓␈α
 Define␈α
the␈αfunction␈α
␈↓↓term␈↓
␈↓ ↓H␈↓by␈αgiving␈α␈↓↓term[e]␈↓␈αthe␈αvalue␈α␈↓αtrue␈↓␈αif␈α␈↓↓e␈↓␈αis␈αan␈αS-expression␈αof␈αthe␈αform␈α␈↓¬(␈↓↓f*␈↓¬␈α(QUOTE␈α␈↓↓a␈↓¬))␈↓␈αfor␈αwhich␈α␈↓↓f[a]␈↓
␈↓ ↓H␈↓terminates␈α⊂and␈α⊂␈↓αfalse␈↓␈α⊂otherwise.␈α⊂ We␈α⊂now␈α⊂ask␈α⊃whether␈α⊂␈↓↓term␈↓␈α⊂is␈α⊂a␈α⊂LISP␈α⊂function,␈α⊂i.e.␈α⊂can␈α⊃it␈α⊂be
␈↓ ↓H␈↓constructed␈α⊂from␈α⊂␈↓↓car,␈↓␈α⊂␈↓↓cdr,␈↓␈α⊂␈↓↓cons,␈↓␈α⊂␈↓↓atom,␈↓␈α⊂ and␈α⊂␈↓↓eq␈↓␈α⊂using␈α⊂␈↓↓λ,␈↓␈α⊂␈↓↓label,␈↓␈α⊂and␈α⊃conditional␈α⊂expressions?
␈↓ ↓H␈↓Well,␈αit␈αcan't,␈αas␈αwe␈αshall␈αshortly␈αprove,␈αand␈αthis␈αmeans␈αthat␈αit␈αis␈αnot␈α␈↓↓computable␈↓␈αwhether␈αa␈αLISP
␈↓ ↓H␈↓calculation␈αterminates,␈αsince␈αif␈α␈↓↓term␈↓␈αwere␈αcomputable␈αby␈αany␈αcomputer␈αor␈αin␈αany␈αrecognized␈αsense,
␈↓ ↓H␈↓it could be represented as a LISP function.  Here is the proof:

␈↓ ↓H␈↓        Consider the function ␈↓↓terma␈↓ defined from ␈↓↓term␈↓ by

␈↓ ↓H␈↓␈↓ β9␈↓↓terma u ← ␈↓αif␈↓↓ term list[u, list[␈↓¬QUOTE, ␈↓↓u]] ␈↓αthen␈↓↓ loop u ␈↓αelse␈↓↓ ␈↓αtrue␈↓↓␈↓, 

␈↓ ↓H␈↓and␈α∞suppose␈α∞that␈α∞␈↓↓f␈↓␈α∞is␈α∞a␈α∞LISP␈α∞function␈α
and␈α∞that␈α∞␈↓↓f*␈↓␈α∞is␈α∞its␈α∞S-expression␈α∞representation.␈α∞ What␈α
is
␈↓ ↓H␈↓␈↓↓terma␈↓␈α␈↓↓f*␈↓␈α?␈αWell␈α␈↓↓terma␈↓␈α␈↓↓f*␈↓␈αtells␈αus␈αwhether␈αthe␈αcomputation␈αof␈α␈↓↓f[f*]␈↓␈αterminates,␈αand␈αit␈αtells␈αus␈αthis
␈↓ ↓H␈↓by␈α∞going␈α∂into␈α∞a␈α∂loop␈α∞if␈α∂␈↓↓f[f*]␈↓␈α∞terminates␈α∂and␈α∞giving␈α∂␈↓αtrue␈↓␈α∞otherwise.␈α∂ Now␈α∞if␈α∂␈↓↓term␈↓␈α∞were␈α∂a␈α∞LISP
␈↓ ↓H␈↓function,␈α
then␈α
␈↓↓terma␈↓␈α
would␈αalso␈α
be␈α
a␈α
LISP␈αfunction.␈α
 Indeed␈α
if␈α
␈↓↓term␈↓␈αwere␈α
represented␈α
by␈α
the␈αS-
␈↓ ↓H␈↓expression ␈↓↓term*,␈↓ then ␈↓↓terma␈↓ would be represented by the S-expression

␈↓ ↓H␈↓␈↓ α→␈↓↓terma*␈↓ = ␈↓¬(LAMBDA (U) (COND ((␈↓↓term*␈↓¬ (LIST U (LIST (QUOTE QUOTE) U))) (LOOP U)) (T T)))␈↓. 

␈↓ ↓H␈↓Now␈α⊂consider␈α∂␈↓↓terma[terma*].␈↓␈α⊂  According␈α∂to␈α⊂the␈α∂definition␈α⊂of␈α∂␈↓↓terma,␈↓␈α⊂this␈α∂will␈α⊂tell␈α⊂us␈α∂whether
␈↓ ↓H␈↓␈↓↓terma[terma*]␈↓␈αis␈αdefined,␈αi.e.␈αit␈αtells␈αabout␈αitself.␈α However,␈αit␈αgives␈αthis␈αanswer␈αin␈αa␈αcontradictory
␈↓ ↓H␈↓way;␈α
namely␈α␈↓↓terma[terma*]␈↓␈α
looping␈α
tells␈αus␈α
that␈α
␈↓↓terma[terma*]␈↓␈αterminates,␈α
and␈α␈↓↓terma[terma*]␈↓␈α
being
␈↓ ↓H␈↓␈↓αtrue␈↓␈α∞tells␈α∞us␈α
that␈α∞␈↓↓terma[terma*]␈↓␈α∞doesn't␈α∞terminate.␈α
 This␈α∞contradiction␈α∞tells␈α∞us␈α
that␈α∞␈↓↓term␈↓␈α∞is␈α∞not␈α
a
␈↓ ↓H␈↓LISP␈α∃function,␈α∃and␈α∃there␈α∃is␈α∃no␈α∀general␈α∃procedure␈α∃for␈α∃telling␈α∃whether␈α∃a␈α∃LISP␈α∀calculation
␈↓ ↓H␈↓terminates.

␈↓ ↓H␈↓        The␈α∩above␈α⊃result␈α∩does␈α⊃not␈α∩exclude␈α⊃LISP␈α∩functions␈α⊃that␈α∩tell␈α⊃whether␈α∩LISP␈α⊃calculations
␈↓ ↓H␈↓terminate.␈α⊃ It␈α⊃just␈α⊃excludes␈α∩perfect␈α⊃ones.␈α⊃ Suppose␈α⊃we␈α⊃have␈α∩a␈α⊃function␈α⊃␈↓↓t␈↓␈α⊃that␈α∩sometimes␈α⊃says
␈↓ ↓H␈↓calculations␈α∂terminate,␈α∞sometimes␈α∂says␈α∂they␈α∞don't␈α∂terminate,␈α∂and␈α∞sometimes␈α∂runs␈α∂on␈α∞indefinitely.
␈↓ ↓H␈↓We␈α
shall␈α
further␈α
assume␈α
that␈α
when␈α
␈↓↓t␈↓␈α
gives␈αan␈α
answer␈α
it␈α
is␈α
always␈α
right.␈α
 Given␈α
such␈α
a␈αfunction␈α
we
␈↓ ↓H␈↓can␈αimprove␈αit␈α
a␈αbit␈αso␈α
that␈αit␈αwill␈α
always␈αgive␈αthe␈α
right␈αanswer␈αwhen␈α
the␈αcalculation␈αit␈α
is␈αasked
␈↓ ↓H␈↓about␈α∪terminates.␈α∪ This␈α∀is␈α∪done␈α∪by␈α∀mixing␈α∪the␈α∪computation␈α∪of␈α∀␈↓↓t[e]␈↓␈α∪with␈α∪a␈α∀computation␈α∪of
␈↓ ↓H␈↓␈↓↓eval[e, ␈↓¬NIL␈↓↓]␈↓␈α∞doing␈α∞the␈α∞computations␈α∂alternately.␈α∞ If␈α∞the␈α∞␈↓↓eval[e, ␈↓¬NIL␈↓↓]␈↓␈α∞computation␈α∂ever␈α∞terminates,
␈↓ ↓H␈↓then the new function asserts termination.

␈↓ ↓H␈↓        Given␈αsuch␈αa␈α␈↓↓t,␈↓␈αwe␈αcan␈αalways␈αfind␈αa␈αcalculation␈αthat␈αdoes␈αnot␈αterminate␈αbut␈α␈↓↓t␈↓␈αdoesn't␈αsay
␈↓ ↓H␈↓so.  The construction is just like that used in the previous proof.  Given ␈↓↓t,␈↓ we construct

␈↓ ↓H␈↓␈↓ βg␈↓↓ta u ← ␈↓αif␈↓↓ t list[u, list[␈↓¬QUOTE, ␈↓↓u]] ␈↓αthen␈↓↓ loop u ␈↓αelse␈↓↓ ␈↓αtrue␈↓↓␈↓, 
␈↓ ↓H␈↓␈↓ ¬hCHAPTER V␈↓ *91


␈↓ ↓H␈↓and␈α
then␈α
we␈α
consider␈α
␈↓↓ta[ta*].␈↓␈α
 If␈α
this␈α
had␈α
the␈α
value␈α
␈↓αtrue␈↓,␈α
then␈α
it␈α
wouldn't␈α
terminate␈α
so␈α
therefore␈α
it
␈↓ ↓H␈↓doesn't␈α⊃terminate␈α⊃but␈α⊂is␈α⊃not␈α⊃one␈α⊂of␈α⊃those␈α⊃expressions␈α⊂which␈α⊃␈↓↓t␈↓␈α⊃decides.␈α⊂ Thus␈α⊃for␈α⊃any␈α⊂partial
␈↓ ↓H␈↓decider␈α∂we␈α∂can␈α∞find␈α∂a␈α∂LISP␈α∂calculation␈α∞which␈α∂doesn't␈α∂terminate␈α∞but␈α∂which␈α∂the␈α∂decider␈α∞doesn't
␈↓ ↓H␈↓decide.  This can in turn be used to get a slightly better decider, namely

␈↓ ↓H␈↓␈↓ βt␈↓↓t␈↓β1␈↓↓[e] ← ␈↓αif␈↓↓ e = ta* ␈↓αthen␈↓↓ ␈↓¬DOESN'T-TERMINATE ␈↓↓ ␈↓αelse␈↓↓ t[e]␈↓. 

␈↓ ↓H␈↓Of␈αcourse,␈α␈↓↓t␈↓␈↓β1␈↓␈αisn't␈αmuch␈αbetter␈αthan␈α␈↓↓t,␈↓␈αsince␈αit␈αcan␈αdecide␈αonly␈αone␈αmore␈αcomputation,␈αbut␈αwe␈αcan
␈↓ ↓H␈↓form␈α␈↓↓t␈↓␈↓β2␈↓␈αby␈αapplying␈αthe␈αsame␈αprocess,␈αand␈αso␈αforth.␈α In␈αfact,␈αwe␈αcan␈αeven␈αform␈α␈↓↓t␈↓␈↓	␈↓#vw␈↓#␈↓␈αwhich␈αdecides
␈↓ ↓H␈↓all␈αthe␈αcases␈αdecided␈αby␈αany␈α␈↓↓t␈↓␈↓βn␈↓.␈α This␈αcan␈αbe␈αfurther␈αimproved␈αby␈αthe␈αsame␈αprocess,␈αetc.␈α How␈αfar
␈↓ ↓H␈↓can␈α∂we␈α∂go?␈α∞ The␈α∂answer␈α∂is␈α∞technical;␈α∂namely,␈α∂the␈α∞improvement␈α∂process␈α∂can␈α∞be␈α∂carried␈α∂out␈α∞any
␈↓ ↓H␈↓recursive ordinal number of times.

␈↓ ↓H␈↓        Unfortunately,␈α⊂this␈α⊂kind␈α∂of␈α⊂improvement␈α⊂seems␈α∂to␈α⊂be␈α⊂superficial,␈α∂since␈α⊂none␈α⊂of␈α⊂the␈α∂new
␈↓ ↓H␈↓computations proved not to terminate are likely to be of practical interest.


␈↓ ↓H␈↓α␈↓ ε
Exercises

␈↓ ↓H␈↓1. Write a function that gives ␈↓↓t␈↓␈↓βn+1␈↓ in terms of ␈↓↓t␈↓␈↓βn␈↓.

␈↓ ↓H␈↓2. Write a function that gives ␈↓↓t␈↓␈↓	␈↓#vw␈↓#␈↓ in terms of ␈↓↓t.␈↓

␈↓ ↓H␈↓3.␈α∞If␈α∞you␈α∞know␈α∞about␈α
Turing␈α∞machines,␈α∞write␈α∞a␈α∞LISP␈α
function␈α∞to␈α∞simulate␈α∞an␈α∞arbitrary␈α
Turing
␈↓ ↓H␈↓machine given a description of the machine in some convenient notation.

␈↓ ↓H␈↓4.␈α
Write␈α
a␈α
LISP␈α
function␈αthat␈α
will␈α
translate␈α
a␈α
Turing␈αmachine␈α
description␈α
into␈α
a␈α
LISP␈αfunction
␈↓ ↓H␈↓that will do the same computation.

␈↓ ↓H␈↓5.␈αIf␈αyou␈αreally␈αlike␈αTuring␈αmachines,␈αwrite␈αa␈αdescription␈αof␈αa␈αTuring␈αmachine␈αthat␈αwill␈αinterpret
␈↓ ↓H␈↓LISP internal notation.
␈↓ ↓H␈↓␈↓ ¬KBIBLIOGRAPHY␈↓ H


␈↓ ↓H␈↓␈↓αFilman,␈α∩R.␈α∪E.␈α∩and␈α∪R.␈α∩W.␈α∪Weyrauch␈α∩(1976)␈↓:␈α∪␈↓↓A␈α∩FOL␈α∪Primer␈↓,␈α∩Stanford␈α∪Artificial␈α∩Intelligence
␈↓ ↓H␈↓Laboratory Memo AIM-288.

␈↓ ↓H␈↓        An excellent introduction to using the automatic first order logic proof checker FOL.

␈↓ ↓H␈↓␈↓αManna, Zohar (1974)␈↓: ␈↓↓Mathematical Theory of Computation␈↓, McGraw-Hill.

␈↓ ↓H␈↓        Chapter␈α2␈αcontains␈αa␈αdiscussion␈αof␈αfirst␈α
order␈αlogic␈αand␈αof␈αthe␈α␈↓↓Natural deduction␈↓␈αmethod␈α
of
␈↓ ↓H␈↓proof.

␈↓ ↓H␈↓        Chapter 5 contains a discussion of functionals and fixedpoints.

␈↓ ↓H␈↓        The␈α
book␈αalso␈α
contains␈α
a␈αdiscussion␈α
of␈αstructural␈α
induction␈α
and␈αother␈α
methods␈α
of␈αproving
␈↓ ↓H␈↓properties of programs.

␈↓ ↓H␈↓␈↓αMcCarthy,␈αJohn␈α(1963)␈↓:␈α"A␈αBasis␈αfor␈αa␈α
Mathematical␈αTheory␈αof␈αComputation",␈αin␈αP.␈αBraffort␈α
and
␈↓ ↓H␈↓D.␈α∩Hirschberg␈α∩(eds.),␈α⊃␈↓↓Computer␈α∩Programming␈α∩and␈α⊃Formal␈α∩Systems␈↓,␈α∩pp.␈α∩33-70.␈α⊃North-Holland
␈↓ ↓H␈↓Publishing Company, Amsterdam.

␈↓ ↓H␈↓        Contains␈α⊃a␈α⊃complete␈α⊃discussion␈α⊃of␈α⊃properties␈α⊃of␈α⊃conditional␈α⊃forms,␈α⊃including␈α⊃cannonical
␈↓ ↓H␈↓forms.  Also discusses computable functionals and recursion induction.

␈↓ ↓H␈↓␈↓αVuillemin,␈αJ.(1973)␈↓:␈α"Proof␈αTechniques␈αfor␈αRecursive␈αPrograms,"␈αPh.D.␈α thesis,␈αComputer␈αScience
␈↓ ↓H␈↓Department, Stanford University, Stanford, Ca..

␈↓ ↓H␈↓␈↓αWeyrauch,␈α
R.␈αW.␈α
(1977)␈↓:␈α "A␈α
users␈α
manual␈αfor␈α
FOL",␈αStanford␈α
Artificial␈α
Intelligence␈αLaboratory
␈↓ ↓H␈↓Memo, AIM-235.1.

␈↓ ↓H␈↓        A manual for the automatic proof checker FOL.
␈↓ ↓H␈↓␈↓ ¬jAPPENDIX I␈↓ ?i


␈↓ ↓H␈↓α␈↓ β@A MICRO-MANUAL FOR LISP - MOSTLY TRUTHFUL

␈↓ ↓H␈↓        LISP␈α
data␈αare␈α
symbolic␈α
expressions␈αthat␈α
can␈αbe␈α
either␈α
␈↓↓atoms␈↓␈αor␈α
␈↓↓lists␈↓.␈α ␈↓↓Atoms␈↓␈α
are␈α
strings␈αof
␈↓ ↓H␈↓letters␈α⊃and␈α⊃digits␈α⊃and␈α⊃other␈α⊃characters␈α⊃not␈α⊃otherwise␈α⊂used␈α⊃in␈α⊃LISP.␈α⊃ A␈α⊃␈↓↓list␈↓␈α⊃consists␈α⊃of␈α⊃a␈α⊂left
␈↓ ↓H␈↓parenthesis␈αfollowed␈α
by␈αzero␈α
or␈αmore␈α
atoms␈αor␈αlists␈α
separated␈αby␈α
spaces␈αand␈α
ending␈αwith␈α
a␈αright
␈↓ ↓H␈↓parenthesis.  Examples: ␈↓¬A, ONION, (), (A), (A ONION A), (PLUS A (TIMES B ONION) 1)␈↓.

␈↓ ↓H␈↓        The␈α↔LISP␈α↔programming␈α↔language␈α↔is␈α↔defined␈α↔by␈α↔rules␈α↔for␈α↔␈↓↓evaluating␈↓␈α↔certain␈α⊗LISP
␈↓ ↓H␈↓expressions␈α∞to␈α
yield␈α∞other␈α
LISP␈α∞expressions␈α∞as␈α
their␈α∞values.␈α
 The␈α∞function␈α
␈↓↓value␈↓␈α∞used␈α∞in␈α
giving
␈↓ ↓H␈↓these␈α
rules␈α
is␈α
not␈α
part␈α
of␈α
the␈α
LISP␈α
language␈α
but␈α
rather␈α
part␈α
of␈α
the␈α
informal␈α
language␈α
in␈α
which
␈↓ ↓H␈↓LISP␈α
is␈αbeing␈α
defined.␈α
 Likewise,␈αthe␈α
italic␈α
letters␈α␈↓↓e␈↓␈α
and␈α
␈↓↓a␈↓␈α(sometimes␈α
with␈α
subscripts)␈αdenote␈α
LISP
␈↓ ↓H␈↓expressions,␈αthe␈αletter␈α␈↓↓v␈↓␈α(usually␈αsubscripted)␈αdenotes␈αan␈αatom␈αserving␈αas␈αa␈αvariable,␈αand␈αthe␈αletter
␈↓ ↓H␈↓␈↓↓f␈↓ stands for a LISP expression serving as a function name.

␈↓ ↓H␈↓1. ␈↓↓value (␈↓¬QUOTE ␈↓↓e) = e␈↓.  For example, the value of ␈↓¬(QUOTE A)␈↓ is ␈↓¬A␈↓.

␈↓ ↓H␈↓2.␈α∪␈↓↓value␈α∪(␈↓¬CAR␈α∪␈↓↓e)␈↓,␈α∪where␈α∪␈↓↓value␈α∪e␈↓␈α∪is␈α∪a␈α∪non-empty␈α∪list,␈α∪is␈α∪the␈α∪first␈α∪element␈α∪of␈α∪␈↓↓value e␈↓.␈α∩ Thus
␈↓ ↓H␈↓␈↓↓value ␈↓¬(CAR (QUOTE (A B C)))␈↓↓ = ␈↓¬A␈↓↓.

␈↓ ↓H␈↓↓3.␈α∞␈↓␈↓↓value␈↓␈α∞(␈↓¬CDR␈α∞␈↓e)␈↓↓,␈↓␈α∞where␈α∞␈↓↓value␈α
e␈↓␈α∞is␈α∞a␈α∞non-empty␈α∞list,␈α∞is␈α
the␈α∞the␈α∞list␈α∞that␈α∞remains␈α∞when␈α∞the␈α
first
␈↓ ↓H␈↓element of ␈↓↓value e␈↓ is deleted.  Thus ␈↓↓value ␈↓¬(CDR (QUOTE (A B C)))␈↓↓ = ␈↓¬(B C)␈↓↓.␈↓

␈↓ ↓H␈↓4.␈α␈↓↓value␈α
(␈↓¬CONS␈α␈↓↓e1␈αe2)␈↓,␈α
is␈αthe␈αlist␈α
that␈αresults␈αfrom␈α
prefixing␈α␈↓↓value e1␈↓␈αonto␈α
the␈αlist␈α
␈↓↓value e2␈↓.␈α Thus
␈↓ ↓H␈↓␈↓↓value ␈↓¬(CONS (QUOTE A) (QUOTE (B C)))␈↓↓ = ␈↓¬(A B C)␈↓↓.␈↓

␈↓ ↓H␈↓5.␈α∃␈↓↓value␈α⊗(␈↓¬EQUAL␈α∃␈↓↓e1␈α∃e2)␈↓␈α⊗is␈α∃␈↓¬T␈↓␈α∃if␈α⊗␈↓↓value␈α∃e1␈α∃=␈α⊗value␈α∃e2␈↓.␈α∃ Otherwise,␈α⊗its␈α∃value␈α∃is␈α⊗␈↓¬NIL␈↓.␈α∃ Thus
␈↓ ↓H␈↓␈↓↓value ␈↓¬(EQUAL (CAR (QUOTE (A B))) (QUOTE A))␈↓↓ = ␈↓¬T␈↓↓␈↓.

␈↓ ↓H␈↓6. ␈↓↓value (␈↓¬ATOM ␈↓↓e) = ␈↓¬T␈↓↓␈↓ if ␈↓↓value e␈↓ is an atom; otherwise its value is ␈↓¬NIL␈↓.

␈↓ ↓H␈↓7.␈α␈↓↓value␈α(␈↓¬COND␈α␈↓↓(p␈↓β1␈↓↓␈αe␈↓β1␈↓↓)␈α...␈α(p␈↓βn␈↓↓␈αe␈↓βn␈↓↓))␈α=␈αvalue␈αe␈↓βi␈↓↓␈↓,␈αwhere␈α␈↓↓p␈↓βi␈↓↓␈↓␈αis␈αthe␈αthe␈αfirst␈αof␈αthe␈α␈↓↓p␈↓'s␈αwhose␈αvalue␈αis␈αnot
␈↓ ↓H␈↓␈↓¬NIL␈↓.  Thus ␈↓↓value ␈↓¬(COND ((ATOM (QUOTE A)) (QUOTE B)) ((QUOTE T) (QUOTE C)))␈↓↓ = ␈↓¬B␈↓↓␈↓.

␈↓ ↓H␈↓8. An atom ␈↓↓v,␈↓ regarded as a variable, may have a value.

␈↓ ↓H␈↓9.␈α␈↓↓value␈α((␈↓¬LAMBDA␈α␈↓↓(v␈↓β1␈↓↓␈α...␈αv␈↓βn␈↓↓)␈αe)␈αe␈↓β1␈↓↓␈α...␈αe␈↓βn␈↓↓)␈↓␈αis␈αthe␈αsame␈αas␈α␈↓↓value e␈↓␈αbut␈αin␈αan␈αenvironment␈αin␈αwhich
␈↓ ↓H␈↓the␈α∞variables␈α∞␈↓↓v␈↓β1␈↓↓ ... v␈↓βn␈↓↓␈↓␈α∞take␈α∞the␈α∞values␈α∂of␈α∞the␈α∞expressions␈α∞␈↓↓e␈↓β1␈↓↓ ... e␈↓βn␈↓↓␈↓␈α∞in␈α∞the␈α∂original␈α∞environment.
␈↓ ↓H␈↓Thus ␈↓↓value ␈↓¬((LAMBDA (X Y) (CONS (CAR X) Y)) (QUOTE (A B)) (CDR (QUOTE (C D))))␈↓↓ = ␈↓¬(A D)␈↓↓␈↓.

␈↓ ↓H␈↓10.␈α⊃Here's␈α⊃the␈α∩hard␈α⊃one.␈α⊃ ␈↓↓value␈α⊃((␈↓¬LABEL␈α∩␈↓↓f␈α⊃(␈↓¬LAMBDA␈α⊃␈↓↓(v␈↓β1␈↓↓␈α⊃...␈α∩v␈↓βn␈↓↓)␈α⊃e))␈α⊃e␈↓β1␈↓↓␈α⊃...␈α∩e␈↓βn␈↓↓)␈↓␈α⊃is␈α⊃the␈α∩same␈α⊃as
␈↓ ↓H␈↓␈↓↓value ((␈↓¬LAMBDA␈α␈↓↓(v␈↓β1␈↓↓ ... v␈↓βn␈↓↓) e) e␈↓β1␈↓↓ ... e␈↓βn␈↓↓)␈↓,␈αbut␈α
whenever␈α␈↓↓(f a␈↓β1␈↓↓␈α... a␈↓βn␈↓↓)␈↓␈αmust␈α
be␈αevaluated,␈α␈↓↓f␈↓␈αis␈α
replaced
␈↓ ↓H␈↓by ␈↓↓(␈↓¬LABEL ␈↓↓f (␈↓¬LAMBDA ␈↓↓(v␈↓β1␈↓↓ ... v␈↓βn␈↓↓) e))␈↓.  Lists beginning with ␈↓¬LABEL ␈↓define functions recursively.

␈↓ ↓H␈↓        This is the core of LISP, and here are more examples:

␈↓ ↓H␈↓␈↓ ∧∃␈↓↓value ␈↓¬(CAR X)␈↓↓ = ␈↓¬(A B)␈↓↓␈↓ if ␈↓↓value ␈↓¬X␈↓↓ = ␈↓¬((A B) C)␈↓↓␈↓, and 

␈↓ ↓H␈↓␈↓ ↓J␈↓↓value␈↓¬((LABEL FF (LAMBDA (X) (COND ((ATOM X) X) ((QUOTE T) (FF (CAR X)))))) (QUOTE ((A B) C)))␈↓↓ = ␈↓¬A␈↓↓.␈↓ 
␈↓ ↓H␈↓ii␈↓ ¬jAPPENDIX I␈↓ H


␈↓ ↓H␈↓Thus␈α␈↓¬((LABEL␈αFF␈α(LAMBDA␈α(X)␈α(COND␈α((ATOM␈αX)␈αX)␈α((QUOTE␈αT)␈α(FF␈α(CAR␈αX))))))␈↓,␈αis␈αthe␈αLISP␈αname␈α
of
␈↓ ↓H␈↓a␈α∞function␈α∂␈↓↓ff␈↓␈α∞such␈α∞that␈α∂␈↓↓ff e␈↓␈α∞is␈α∂the␈α∞first␈α∞atom␈α∂in␈α∞the␈α∞written␈α∂form␈α∞of␈α∂␈↓↓e.␈↓␈α∞Note␈α∞that␈α∂the␈α∞list␈α∂␈↓↓ff␈↓␈α∞is
␈↓ ↓H␈↓substituted for the atom ␈↓¬FF ␈↓twice in the course of evaluating the above expression.

␈↓ ↓H␈↓Difficult mathematical type exercise: Find a list ␈↓↓e␈↓ such that ␈↓↓value e = e␈↓.

␈↓ ↓H␈↓        You␈αmay␈α
now␈αprogram␈αin␈α
LISP.␈α Call␈αLISP␈α
system␈αon␈αa␈α
time-sharing␈αcomputer,␈αtype␈α
in␈αa
␈↓ ↓H␈↓list, and LISP will type back its value.


␈↓ ↓H␈↓αAbbreviations

␈↓ ↓H␈↓        The above LISP needs some abbreviations for practical use.

␈↓ ↓H␈↓1.␈αSo␈αas␈αnot␈αto␈αdescribe␈αa␈αLISP␈αfunction␈αeach␈αtime␈αit␈αis␈αused,␈αwe␈αdefine␈αit␈αpermanently␈αby␈αtyping
␈↓ ↓H␈↓␈↓↓(␈↓¬DEFUN␈α∂␈↓↓f (v␈↓β1␈↓↓ ... v␈↓βn␈↓↓) e)␈↓.␈α⊂ Thereafter␈α∂␈↓↓(f e␈↓β1␈↓↓ ... e␈↓βn␈↓↓)␈↓␈α⊂is␈α∂evaluated␈α⊂by␈α∂evaluating␈α⊂␈↓↓e␈↓␈α∂with␈α⊂the␈α∂variables
␈↓ ↓H␈↓␈↓↓v␈↓β1␈↓↓, ... ,v␈↓βn␈↓↓␈↓␈α→taking␈α→the␈α→values␈α→␈↓↓value e␈↓β1␈↓↓, ... ,value e␈↓βn␈↓↓␈↓␈α→respectively.␈α→ Thus,␈α→after␈α→we␈α→define
␈↓ ↓H␈↓␈↓¬(DEFUN FF (X) (COND ((ATOM X) X) ((QUOTE T) (FF (CAR X)))))␈↓,␈α⊃typing␈α⊃ ␈↓¬(FF (QUOTE ((A B) C)))␈↓,␈α∩gets␈α⊃␈↓¬A␈↓
␈↓ ↓H␈↓from LISP.

␈↓ ↓H␈↓2.␈αThe␈αvariables␈α␈↓¬T␈↓␈αand␈α␈↓¬NIL␈↓␈αare␈αpermanently␈αassigned␈αthe␈αvalues␈α␈↓¬T␈↓␈αand␈α␈↓¬NIL␈↓,␈αand␈α␈↓¬NIL␈↓␈αis␈αthe␈αname␈αof
␈↓ ↓H␈↓the␈α:null␈α9list␈α:().␈α: Therefore,␈α9the␈α:above␈α9definition␈α:can␈α:be␈α9written
␈↓ ↓H␈↓␈↓¬(DEFUN FF (X) (COND ((ATOM X) X) (T (FF (CAR X)))))␈↓.

␈↓ ↓H␈↓3. We have the permanent function definitions

␈↓ ↓H␈↓                ␈↓¬(DEFUN NULL (X) (EQUAL X NIL))␈↓ and ␈↓¬(DEFUN CADR (X) (CAR (CDR X)))␈↓,

␈↓ ↓H␈↓and similarly for arbitrary combinations of ␈↓¬A␈↓ and ␈↓¬D␈↓.

␈↓ ↓H␈↓4. ␈↓↓(␈↓¬LIST ␈↓↓e␈↓β1␈↓↓ ... e␈↓βn␈↓↓)␈↓ is defined for each ␈↓↓n␈↓ to be ␈↓↓(␈↓¬CONS ␈↓↓e␈↓β1␈↓↓ (␈↓¬CONS ␈↓↓... (␈↓¬CONS ␈↓↓e␈↓βn␈↓↓ ␈↓¬NIL␈↓↓)))␈↓.

␈↓ ↓H␈↓5.␈α␈↓↓(␈↓¬AND␈α␈↓↓p␈αq)␈↓␈αabbreviates␈α␈↓↓(␈↓¬COND␈α␈↓↓(p q) (␈↓¬T␈↓↓ ␈↓¬NIL␈↓↓))␈↓.␈α
 ␈↓¬AND␈↓s␈αwith␈αmore␈αterms␈αare␈αdefined␈αsimilarly,␈αand␈α
the
␈↓ ↓H␈↓propositional connectives ␈↓¬OR␈↓ and ␈↓¬NOT␈↓ abbreviate similar conditional expressions.

␈↓ ↓H␈↓        Now we can give some further examples of LISP function definitions:

␈↓ ↓H␈↓␈↓¬(DEFUN ALT (X) (COND ((OR (NULL X) (NULL (CDR X))) X) (T (CONS (CAR X) (ALT (CDDR X))))))␈↓

␈↓ ↓H␈↓defines␈α∂a␈α∂function␈α∂that␈α∂gives␈α∂alternate␈α∂elements␈α∂of␈α∂a␈α∂list␈α∂starting␈α∂with␈α∂the␈α∂first␈α⊂element.␈α∂ Thus
␈↓ ↓H␈↓␈↓¬(ALT (QUOTE (A B C D E)))␈↓ = ␈↓¬(A C E)␈↓.

␈↓ ↓H␈↓        ␈↓¬(DEFUN SUBST (X Y Z) (COND ((ATOM Z) (COND ((EQUAL Z Y) X) (T Z)))␈↓
␈↓ ↓H␈↓                                       ␈↓¬(T (CONS (SUBST X Y (CAR Z)) (SUBST X Y (CDR Z))))))␈↓

␈↓ ↓H␈↓gives the result of substituting ␈↓¬X␈↓ for ␈↓¬Y␈↓ in ␈↓¬Z␈↓.  Thus

␈↓ ↓H␈↓        ␈↓¬(SUBST (QUOTE (PLUS X Y)) (QUOTE V) (QUOTE (TIMES X V)))␈↓ = ␈↓¬(TIMES X (PLUS X Y))␈↓.
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ ?i


␈↓ ↓H␈↓α␈↓ ∧BExamples of Computer-checked proofs

␈↓ ↓H␈↓        In␈α⊂chapter␈α∂3␈α⊂we␈α∂showed␈α⊂how␈α∂to␈α⊂prove␈α∂that␈α⊂certain␈α∂recursive␈α⊂LISP␈α∂programs␈α⊂meet␈α∂their
␈↓ ↓H␈↓specifications.␈α The␈αtechniques␈αpresented␈αin␈αthat␈αchapter␈αrequire␈αfurther␈αdevelopment␈αbefore␈αthey
␈↓ ↓H␈↓can␈αbe␈α
economically␈αapplied␈α
to␈αlarge␈α
programs.␈α One␈α
requirement␈αis␈α
that␈αthe␈α
proofs␈αbe␈αchecked␈α
by
␈↓ ↓H␈↓computer,␈α∞since␈α∞there␈α∞is␈α∞just␈α∞as␈α∞much␈α∞opportunity␈α∞for␈α∞wishful␈α∞thinking␈α∞in␈α∞writing␈α∞or␈α∂reading␈α∞a
␈↓ ↓H␈↓proof of correctness as there is in writing the program in the first place.

␈↓ ↓H␈↓        This␈α∞appendix␈α
contains␈α∞proofs␈α
of␈α∞the␈α∞correctness␈α
of␈α∞␈↓↓samefringe␈↓␈α
in␈α∞a␈α
form␈α∞acceptable␈α∞to␈α
a
␈↓ ↓H␈↓first␈α∀order␈α∀logic␈α∃proof-checker␈α∀called␈α∀FOL␈α∀developed␈α∃at␈α∀the␈α∀Stanford␈α∃University␈α∀Artificial
␈↓ ↓H␈↓Intelligence␈α∩Laboratory.␈α∩ An␈α∩FOL␈α⊃proof␈α∩is␈α∩organized␈α∩into␈α⊃several␈α∩parts.␈α∩ The␈α∩object␈α∩of␈α⊃this
␈↓ ↓H␈↓organization␈α∂is␈α∂first␈α∞to␈α∂establish␈α∂the␈α∞language␈α∂in␈α∂which␈α∞the␈α∂proof␈α∂is␈α∞made,␈α∂then␈α∂to␈α∂present␈α∞the
␈↓ ↓H␈↓general␈αaxioms␈αof␈αthe␈αfield␈αof␈αreasoning␈α(LISP␈αprograms␈αin␈αthe␈αpresent␈αcase),␈αthen␈αto␈αpresent␈αthe
␈↓ ↓H␈↓facts␈α
about␈α
the␈α
particular␈α
problem␈α
(the␈α
function␈α
definitions␈α
in␈α
present␈α
case),␈α
and␈α
finally␈α
to␈αgive␈α
the
␈↓ ↓H␈↓proof␈α
itself.␈α
 If␈α
the␈α
stage␈α
has␈α
been␈α
properly␈α
set,␈α
the␈α
proof␈α
itself␈α
will␈α
be␈α
short␈α
and␈αcomprehensible␈α
as
␈↓ ↓H␈↓well as acceptable to the computer.


␈↓ ↓H␈↓αIntroduction to FOL

␈↓ ↓H␈↓        We␈α∩give␈α∪here␈α∩a␈α∩very␈α∪brief␈α∩introduction␈α∩to␈α∪FOL␈α∩intended␈α∩only␈α∪to␈α∩help␈α∩the␈α∪reader␈α∩to
␈↓ ↓H␈↓understand␈α∩the␈α⊃"FOL␈α∩proofs"␈α⊃that␈α∩follow.␈α⊃ The␈α∩␈↓↓FOL␈↓␈α⊃␈↓↓Primer␈↓␈α∩(Filman␈α⊃and␈α∩Weyrauch␈α⊃(1976))
␈↓ ↓H␈↓provides␈α∂an␈α∞excellent␈α∂introduction␈α∞to␈α∂the␈α∞use␈α∂of␈α∞FOL.␈α∂ A␈α∞more␈α∂detailed␈α∞description␈α∂of␈α∂FOL␈α∞is
␈↓ ↓H␈↓contained in (Weyrauch 1977).

␈↓ ↓H␈↓        FOL␈αchecks␈αproofs␈αwritten␈αin␈αa␈αnatural␈αdeduction␈αstyle␈αin␈αessentially␈αa␈αfirst␈αorder␈αlanguage.
␈↓ ↓H␈↓The␈α∂language␈α∂is␈α∂specified␈α∂by␈α∂declaring␈α∂all␈α∂of␈α∂the␈α∂variable␈α∂and␈α∂constant␈α∂symbols␈α∂that␈α∂that␈α∂will
␈↓ ↓H␈↓appear.␈α∪ Additional␈α∪information␈α∪may␈α∪be␈α∪included␈α∪in␈α∪the␈α∪declarations␈α∪such␈α∪as␈α∪the␈α∀range␈α∪of
␈↓ ↓H␈↓induvidual variables and the domain and range of operators.  Thus the commands

␈↓ ↓H␈↓                ␈↓¬DECLARE  PREDCONST  ISSEXP 1 [PRE];␈↓

␈↓ ↓H␈↓                ␈↓¬DECLARE  INDVAR X Y Z ε ISSEXP;␈↓

␈↓ ↓H␈↓tell␈αFOL␈αthat␈α␈↓¬ISSEXP␈α␈↓is␈αa␈αpredicate␈αwith␈αone␈αargument␈αused␈αas␈αa␈αprefix,␈αand␈αthat␈α␈↓¬X,␈α␈↓␈↓¬Y,␈α␈↓and␈α␈↓¬Z␈α␈↓are
␈↓ ↓H␈↓individual␈α⊗variables␈α⊗ranging␈α⊗over␈α⊗the␈α∃domain␈α⊗with␈α⊗characteristic␈α⊗predicate␈α⊗␈↓¬ISSEXP.␈α⊗␈↓␈α∃This
␈↓ ↓H␈↓declaration also implicitly entails such axioms as ␈↓¬∀X: ISSEXP X␈↓.  The command

␈↓ ↓H␈↓                ␈↓¬DECLARE OPCONST  CONS (ISSEXP,ISSEXP) = ISSEXP;␈↓

␈↓ ↓H␈↓tells␈αFOL␈αthat␈α␈↓¬CONS␈α␈↓is␈αa␈αfunction␈αtaking␈αtwo␈αarguments.␈α Both␈αmust␈αsatisfy␈α␈↓¬ISSEXP␈αand␈α␈↓the␈αaxiom
␈↓ ↓H␈↓␈↓¬∀X Y: ISSEXP CONS(X,Y)␈↓␈αis␈αimplied.␈α
 The␈αextra␈αinformation␈αabout␈α
domains␈αand␈αranges␈αcontained␈α
in
␈↓ ↓H␈↓the␈α∞declarations␈α∞is␈α∞part␈α∂of␈α∞the␈α∞"sorting"␈α∞mechanism␈α∞of␈α∂FOL␈α∞and␈α∞enables␈α∞a␈α∞certain␈α∂ammount␈α∞of
␈↓ ↓H␈↓automatic checking to be carried out when expressions are substituted for "sorted" variables.

␈↓ ↓H␈↓        The general axioms and problem specific facts are given by commands of the form

␈↓ ↓H␈↓                ␈↓¬AXIOM   <axiom name>:  <wff>;;␈↓
␈↓ ↓H␈↓ii␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓where ␈↓¬<wff> ␈↓is any sentence of the language which you wish to take as an axiom.

␈↓ ↓H␈↓        The␈α⊂actual␈α⊂proof␈α⊂consists␈α⊂of␈α⊂a␈α⊃sequence␈α⊂of␈α⊂commands␈α⊂intended␈α⊂to␈α⊂generate␈α⊃proof␈α⊂steps.
␈↓ ↓H␈↓When␈αFOL␈αaccepts␈αa␈αcommand␈αand␈αgenerates␈αa␈αnew␈αproof␈αstep,␈αit␈αreplies␈αgiving␈αthe␈αline number
␈↓ ↓H␈↓assigned␈αto␈α
that␈αstep,␈αthe␈α
sentence␈αproved␈αby␈α
the␈αstep␈αand␈α
a␈αlist␈αof␈α
line numbers␈αof␈αassumptions,␈α
if
␈↓ ↓H␈↓any,␈α∂upon␈α∂which␈α∂the␈α∂proof␈α∂step␈α∂depends.␈α∂ The␈α∂rules␈α∂of␈α∂inference␈α∂of␈α∂FOL␈α∂which␈α∂allow␈α∂you␈α∂to
␈↓ ↓H␈↓generate a new proof step from those previously generated are of several types.

␈↓ ↓H␈↓        First␈α∞are␈α∂the␈α∞rules␈α∂of␈α∞natural␈α∂deduction␈α∞consisting␈α∂of␈α∞an␈α∂introduction␈α∞and␈α∂an␈α∞elimination
␈↓ ↓H␈↓rule for each of the locigal connectives and quantifiers.  For example

␈↓ ↓H␈↓                ␈↓¬⊃E   <step1>   <step2>;␈↓

␈↓ ↓H␈↓generates␈α⊃the␈α⊃step␈α⊂proving␈α⊃␈↓¬<wff2>␈α⊃␈↓using␈α⊂the␈α⊃⊃ elimination␈α⊃rule␈α⊂if␈α⊃␈↓¬<step1>␈α⊃␈↓proves␈α⊃␈↓¬<wff1>␈α⊂␈↓and
␈↓ ↓H␈↓␈↓¬<step2> ␈↓proves  ␈↓¬<wff1> ⊃ <wff2>␈↓.

␈↓ ↓H␈↓                ␈↓¬∀I   <step>   <var>;␈↓

␈↓ ↓H␈↓generates the step  ␈↓¬∀<var>: <wff>␈↓  where ␈↓¬<step> ␈↓proves ␈↓¬<wff> ␈↓using the ∀ introduction rule.

␈↓ ↓H␈↓        Next␈α⊃there␈α⊃are␈α∩rules␈α⊃which␈α⊃correspond␈α⊃to␈α∩decision␈α⊃procedures␈α⊃for␈α⊃special␈α∩cases.␈α⊃ These
␈↓ ↓H␈↓include␈α∞␈↓¬TAUT␈α∂␈↓␈↓¬(TAUTEQ)␈α∞␈↓for␈α∞deductions␈α∂using␈α∞only␈α∞rules␈α∂of␈α∞propositional␈α∞calculus␈α∂(with␈α∞equality)
␈↓ ↓H␈↓and␈α∃␈↓¬MONADIC␈α∀␈↓for␈α∃deductions␈α∀needing␈α∃only␈α∀facts␈α∃about␈α∀unary␈α∃predicates.␈α∀ For␈α∃example␈α∀the
␈↓ ↓H␈↓command

␈↓ ↓H␈↓                ␈↓¬TAUT   <wff>   <list of steps and axioms>;␈↓

␈↓ ↓H␈↓will␈αproduce␈αthe␈αstep␈αproving␈α␈↓¬<wff>␈α␈↓if␈αthe␈αdecision␈αprocedure␈α␈↓¬TAUT␈α␈↓determines␈αthat␈α␈↓¬<wff>␈α␈↓follows
␈↓ ↓H␈↓from the list of steps and axoms.

␈↓ ↓H␈↓        Finally␈α∞there␈α∞are␈α∞the␈α∞rules␈α∞␈↓¬ASSUME␈α∞␈↓which␈α
allows␈α∞you␈α∞to␈α∞make␈α∞an␈α∞assumption,␈α∞␈↓¬SUBST␈α
␈↓and
␈↓ ↓H␈↓␈↓¬SUBSTR␈α⊂␈↓which␈α⊃allow␈α⊂substitution␈α⊃of␈α⊂a␈α⊃term␈α⊂(sentence)␈α⊃by␈α⊂one␈α⊃that␈α⊂is␈α⊃equal␈α⊂(equivalent)␈α⊃to␈α⊂it,
␈↓ ↓H␈↓␈↓¬REWRITE␈α␈↓which␈αcorresponds␈αto␈αdeduction␈αby␈αa␈αchain␈αof␈αequalities,␈αand␈α␈↓¬SIMPLIFY␈α␈↓which␈αfor␈αpresent
␈↓ ↓H␈↓purposes␈α∃gives␈α∃access␈α∃to␈α∃the␈α∃axioms␈α∃implied␈α∃by␈α∃the␈α∃sorting␈α∃information␈α∃contained␈α⊗in␈α∃the
␈↓ ↓H␈↓declarations.

␈↓ ↓H␈↓        The␈α∂conventions␈α∞used␈α∂in␈α∞FOL␈α∂to␈α∂denote␈α∞sentences␈α∂and␈α∞terms␈α∂of␈α∞the␈α∂language␈α∂and␈α∞proof
␈↓ ↓H␈↓steps␈αare␈αthe␈αfollowing.␈α A␈αproof␈αstep␈αcan␈αbe␈αgiven␈αa␈αname␈αby␈αthe␈αcommand␈α␈↓¬LABEL.␈α␈↓A␈αproof␈αstep
␈↓ ↓H␈↓can␈α
thus␈αbe␈α
be␈α
referred␈αto␈α
by␈α
its␈αline-number,␈α
its␈α
name␈α(if␈α
any)␈α
and␈αalso␈α
by␈α
a␈αstring␈α
of␈α
↑'s␈αwhere␈α
␈↓↓n␈↓
␈↓ ↓H␈↓↑'s␈α
refers␈αto␈α
the␈α␈↓↓n␈↓th␈α
previous␈αline.␈α
 In␈αthe␈α
case␈αof␈α
axioms,␈αif␈α
several␈αaxioms␈α
are␈αdefined␈α
in␈αa␈α
group
␈↓ ↓H␈↓with␈αname␈α<axname>␈αthe␈αthe␈α␈↓↓i␈↓th␈αaxiom␈αof␈αthe␈αgroup␈αis␈αreferred␈αto␈αas␈α<axname>i.␈α Sentences␈αand
␈↓ ↓H␈↓terms␈α
of␈α
the␈α
language␈α
can␈αbe␈α
given␈α
explicitly␈α
or␈α
by␈α
referring␈αto␈α
the␈α
<wff>␈α
(or␈α
a␈α
subpart␈αthereof)␈α
of
␈↓ ↓H␈↓a␈α
step␈α
or␈α
axiom.␈α
 If␈α
␈↓↓l␈↓␈α
refers␈α
to␈α
a␈α
proof␈α
step␈α
or␈α
an␈α
axiom␈α
then␈α
 ␈↓↓l:␈↓␈α
 refers␈α
to␈α
the␈α
corresponding␈α
<wff>.
␈↓ ↓H␈↓If␈α
the␈α
outermost␈αconnective,␈α
predicate␈α
or␈αoperator␈α
is␈α
␈↓↓k␈↓-ary.␈αThen␈α
 ␈↓↓l:#i␈↓␈α
 for␈α␈↓↓1 ≤ i ≤ k␈↓␈α
refers␈α
to␈αthe
␈↓ ↓H␈↓␈↓↓i␈↓th subpart of the expresstion and  ␈↓↓l:#i#j␈↓  refers to the ␈↓↓j␈↓th subpart of the ␈↓↓i␈↓th subpart, etc..

␈↓ ↓H␈↓        The␈α∞format␈α∞used␈α
for␈α∞presenting␈α∞a␈α
proof␈α∞checked␈α∞by␈α
FOL␈α∞is␈α∞as␈α
follows.␈α∞ The␈α∞axioms␈α
and
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ -iii


␈↓ ↓H␈↓declarations␈αare␈αgiven␈αfirst.␈α These␈αare␈αtaken␈αdirectly␈αfrom␈αthe␈αfiles␈αread␈αby␈αFOL.␈α Following␈αthis
␈↓ ↓H␈↓the␈α
command␈αfiles␈α
for␈α
the␈αvarious␈α
portions␈αof␈α
the␈α
proof␈αare␈α
given.␈α Each␈α
file␈α
starts␈αa␈α
new␈αproof␈α
in
␈↓ ↓H␈↓the␈α∂environment␈α∂of␈α∞the␈α∂axioms␈α∂and␈α∞delcarations.␈α∂ Hence␈α∂some␈α∞of␈α∂the␈α∂files␈α∞begin␈α∂with␈α∂a␈α∂list␈α∞of
␈↓ ↓H␈↓additional␈αaxioms␈αcorresponding␈αto␈αpreviously␈α
proved␈αresults␈αwhich␈αare␈αneeded.␈α
 The␈αcommands
␈↓ ↓H␈↓for␈α⊂generating␈α⊂proof␈α⊂steps␈α⊂are␈α⊂interspersed␈α⊃with␈α⊂the␈α⊂generated␈α⊂steps.␈α⊂ In␈α⊂general␈α⊂only␈α⊃the␈α⊂key
␈↓ ↓H␈↓generated␈α∃steps␈α∃are␈α∃included␈α∃to␈α∃make␈α∀the␈α∃proof␈α∃read␈α∃more␈α∃like␈α∃the␈α∃informal␈α∀counterpart.
␈↓ ↓H␈↓Commands␈α∀and␈α∀generated␈α∀steps␈α∀are␈α∀in␈α∪different␈α∀fonts␈α∀so␈α∀they␈α∀can␈α∀be␈α∀easily␈α∪distinguished.
␈↓ ↓H␈↓Commands␈α
are␈α
separated␈α
by␈α
";"␈α
and␈α
more␈α
than␈α
one␈α
may␈α
appear␈α
on␈α
a␈α
line.␈α
 The␈α
<wff>␈α
argument␈α
to
␈↓ ↓H␈↓the␈α∂higher␈α∂level␈α∞commands␈α∂is␈α∂omitted␈α∞as␈α∂it␈α∂can␈α∞be␈α∂deduced␈α∂from␈α∞the␈α∂generated␈α∂step␈α∞following.
␈↓ ↓H␈↓The␈α
generated␈α
step␈α∞consists␈α
of␈α
the␈α∞line␈α
number␈α
followed␈α
by␈α∞the␈α
<wff>␈α
followed␈α∞by␈α
a␈α
list␈α∞of␈α
line
␈↓ ↓H␈↓numbers␈αof␈α
assumptions␈αon␈α
which␈αthe␈αstep␈α
depends,␈αif␈α
any.␈α If␈αthe␈α
step␈αhas␈α
been␈αlabeled,␈αthe␈α
label
␈↓ ↓H␈↓appears␈αat␈αthe␈αbeginning␈αof␈αthe␈αline␈αand␈αthe␈αlabel␈αcommand␈αis␈αnot␈αshown.␈α Comments␈αappear␈αin
␈↓ ↓H␈↓bold␈α∞face␈α∞print␈α∞and␈α∞serve␈α∞to␈α∞name␈α∞the␈α∞lemma␈α∞or␈α∞theorem␈α∞being␈α∞proved␈α∞as␈α∞well␈α∞as␈α∞providing␈α∞a
␈↓ ↓H␈↓guide to the organization of the proof.
␈↓ ↓H␈↓iv␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓α␈↓ ∧)FOL Proof of the SAMEFRINGE theorem.

␈↓ ↓H␈↓α␈↓ ∧5First order axioms for S-EXPRESSIONS

␈↓ ↓H␈↓¬DECLARE PREDCONST ISSEXP ISLIST ATOM NULL 1 [PRE];
␈↓ ↓H␈↓¬DECLARE OPCONST CAR CDR 1 [PRE];
␈↓ ↓H␈↓¬DECLARE OPCONST CONS (ISSEXP,ISSEXP) = ISSEXP;

␈↓ ↓H␈↓¬MOREGENERAL ATOM ≥ {NULL};
␈↓ ↓H␈↓¬MOREGENERAL ISLIST ≥ {NULL};
␈↓ ↓H␈↓¬MOREGENERAL ISSEXP ≥ {ISLIST, ATOM, NULL};


␈↓ ↓H␈↓¬DECLARE INDVAR XX YY;
␈↓ ↓H␈↓¬DECLARE INDVAR X X1 Y Y1 ε ISSEXP;
␈↓ ↓H␈↓¬DECLARE INDVAR U V W ε ISLIST;
␈↓ ↓H␈↓¬DECLARE INDCONST NNIL ε NULL;
␈↓ ↓H␈↓¬DECLARE INDCONST BOTTOM;
␈↓ ↓H␈↓¬DECLARE PREDPAR PHI 1;


␈↓ ↓H␈↓¬AXIOM SEXP:
␈↓ ↓H␈↓¬        SORTAX:         ∀U. ISSEXP U;
␈↓ ↓H␈↓¬        ATOMDF:         ¬ISSEXP BOTTOM,
␈↓ ↓H␈↓¬                        ∀U.(NULL U ≡ ATOM U),
␈↓ ↓H␈↓¬                        ∀U.(NULL U ≡ U=NNIL);
␈↓ ↓H␈↓¬        CARDEF:         ∀X.(¬ATOM X ⊃ ISSEXP CAR X),
␈↓ ↓H␈↓¬                        ∀X Y.(X = CAR CONS(X, Y));
␈↓ ↓H␈↓¬        CDRDEF:         ∀X.(¬ATOM X ⊃ ISSEXP CDR X),
␈↓ ↓H␈↓¬                        ∀X Y.(Y = CDR CONS(X, Y)),
␈↓ ↓H␈↓¬                        ∀U.(¬NULL U ⊃ ISLIST CDR U);
␈↓ ↓H␈↓¬        CONSDF:         ∀X U.(ISLIST CONS(X, U)),
␈↓ ↓H␈↓¬                        ∀X Y.(ISSEXP CONS(X, Y)),
␈↓ ↓H␈↓¬                        ∀X Y.(¬ATOM CONS(X, Y)),
␈↓ ↓H␈↓¬                        ∀X.(¬ATOM X ⊃ X = CONS(CAR X, CDR X));
␈↓ ↓H␈↓¬        ;;
␈↓ ↓H␈↓¬AXIOM LISTINDUCTION:
␈↓ ↓H␈↓¬        ∀U.(NULL U ⊃ PHI(U)) ∧ ∀U.(¬NULL U ∧ PHI(CDR U) ⊃ PHI(U)) ⊃ ∀U.PHI(U);;
␈↓ ↓H␈↓¬AXIOM SEXPINDUCTION:
␈↓ ↓H␈↓¬        ∀X.(ATOM X ⊃ PHI(X)) ∧ ∀X.(¬ATOM X ∧ PHI(CAR X) ∧ PHI(CDR X) ⊃ PHI(X)) ⊃ ∀X.PHI(X);;


␈↓ ↓H␈↓αAlternate Axioms

␈↓ ↓H␈↓¬AXIOM SEXP_ALT:
␈↓ ↓H␈↓¬        CARCONS:        ∀X Y. (CAR CONS(X, Y) = X);
␈↓ ↓H␈↓¬        CDRCONS:        ∀X Y. (CDR CONS(X, Y) = Y);
␈↓ ↓H␈↓¬        EQSEXP:         ∀X Y. ((¬ATOM X ∧ ¬ATOM Y) ⊃ (CAR X = CAR Y ∧ CDR X = CDR Y ≡ X = Y));
␈↓ ↓H␈↓¬        ;;
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ 7v


␈↓ ↓H␈↓α␈↓ ∧XAxioms for Extended Truth Values

␈↓ ↓H␈↓¬DECLARE PREDCONST ISTV ISETV 1 [PRE];
␈↓ ↓H␈↓¬DECLARE OPCONST AAND OOR EEQ 2 [INF];
␈↓ ↓H␈↓¬DECLARE OPCONST NNOT AATOM  1 [PRE];

␈↓ ↓H␈↓¬MOREGENERAL ISETV ≥ {ISTV};
␈↓ ↓H␈↓¬DECLARE INDCONST T F ε ISTV;
␈↓ ↓H␈↓¬DECLARE INDVAR P Q εISTV;
␈↓ ↓H␈↓¬DECLARE INDVAR PP QQ εISETV;
␈↓ ↓H␈↓¬AXIOM ETV:
␈↓ ↓H␈↓¬        ETVB:   ISETV BOTTOM;
␈↓ ↓H␈↓¬        ETVEXT: ∀PP.(PP=T ∨ PP=F ∨ PP=BOTTOM);
␈↓ ↓H␈↓¬        TVEXT:  ∀P.(P=T ∨ P=F);
␈↓ ↓H␈↓¬        TISNTF: ¬(T=F);
␈↓ ↓H␈↓¬        TISNTB: ¬(T=BOTTOM);
␈↓ ↓H␈↓¬        FISNTB: ¬(F=BOTTOM);
␈↓ ↓H␈↓¬        NOTDEF: ∀PP.(NNOT PP = IF (PP=BOTTOM) THEN BOTTOM ELSE IF (PP=T) THEN F ELSE T);
␈↓ ↓H␈↓¬        ANDDEF: ∀PP QQ.(PP AAND QQ = IF (PP=BOTTOM) THEN BOTTOM
␈↓ ↓H␈↓¬                                                ELSE IF (PP=T) THEN QQ ELSE F);
␈↓ ↓H␈↓¬        ORDEF:  ∀PP QQ.(PP OOR QQ = IF (PP=BOTTOM) THEN BOTTOM ELSE IF PP=T THEN T ELSE QQ);
␈↓ ↓H␈↓¬        EQUDEF: ∀XX YY.(XX EEQ YY =  IF (¬ISSEXP XX ∨ ¬ISSEXP YY) THEN BOTTOM
␈↓ ↓H␈↓¬                                                ELSE IF (XX = YY) THEN T ELSE F);
␈↓ ↓H␈↓¬        ATDEF:  ∀XX.(AATOM XX = IF (¬ISSEXP XX) THEN BOTTOM ELSE IF ATOM XX THEN T ELSE F);
␈↓ ↓H␈↓¬        ;;


␈↓ ↓H␈↓α␈↓ ¬&Axioms for NATNUMS


␈↓ ↓H␈↓¬DECLARE INDVAR K L M N ε NATNUM;
␈↓ ↓H␈↓¬DECLARE PREDCONST < 2 [INF];
␈↓ ↓H␈↓¬DECLARE OPCONST + 2 [INF];
␈↓ ↓H␈↓¬DECLARE PREDPAR PSI 1;

␈↓ ↓H␈↓¬AXIOM NUMB:
␈↓ ↓H␈↓¬        ISTOT_PLUS:     ∀M N.NATNUM (M+N);
␈↓ ↓H␈↓¬        ASSOC:          ∀L M N.(L+(M+N)=(L+M)+N);
␈↓ ↓H␈↓¬        ORDER_PLUS:     ∀K L M N.(((K<L)∧(M<N))⊃(K+M<L+N));
␈↓ ↓H␈↓¬        ORDER:          ∀N.N<1+N;
␈↓ ↓H␈↓¬        ;;

␈↓ ↓H␈↓¬AXIOM NUMBINDUCTION:    ∀N.(∀M.(M<N⊃PSI(M))⊃PSI(N)) ⊃ ∀N.PSI(N);;
␈↓ ↓H␈↓vi␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓α␈↓ ∧YFunction and Predicate Definitions

␈↓ ↓H␈↓¬DECLARE OPCONST FRINGE GOPHER SIZE 1 [PRE];
␈↓ ↓H␈↓¬DECLARE OPCONST * 2 [INF];
␈↓ ↓H␈↓¬DECLARE PREDCONST SAMEFRINGE SAME THM 2;
␈↓ ↓H␈↓¬DECLARE OPCONST SAMEFRINGEA SAMEA 2;


␈↓ ↓H␈↓¬DEFINE FUNCTIONS_AND_PREDICATES:
␈↓ ↓H␈↓¬        APPENDDEF:
␈↓ ↓H␈↓¬                ∀U V.(U * V = IF (NULL U) THEN V ELSE CONS(CAR U, (CDR U) * V));
␈↓ ↓H␈↓¬        SIZEDEF:
␈↓ ↓H␈↓¬                ∀X.(SIZE X  =IF ATOM X THEN 1 ELSE (SIZE CAR X)+(SIZE CDR X));
␈↓ ↓H␈↓¬        FRINGEDEF:
␈↓ ↓H␈↓¬                ∀X.(FRINGE X = IF (ATOM X) THEN CONS(X,NNIL) ELSE (FRINGE CAR X) * (FRINGE CDR X));
␈↓ ↓H␈↓¬        SAMEFRINGEDEF:
␈↓ ↓H␈↓¬                ∀X Y.(SAMEFRINGE(X,Y) ≡ (SAMEFRINGEA(X,Y) = T));
␈↓ ↓H␈↓¬        SAMEFRINGEADEF:
␈↓ ↓H␈↓¬                ∀X Y.(SAMEFRINGEA(X,Y) = (X EEQ Y) OOR (((NNOT AATOM X) AAND (NNOT AATOM Y))
␈↓ ↓H␈↓¬                                                        AAND SAMEA(GOPHER X, GOPHER Y)));
␈↓ ↓H␈↓¬        SAMEDEF:
␈↓ ↓H␈↓¬                ∀X Y.(SAME(X,Y) ≡ (SAMEA(X,Y) = T));
␈↓ ↓H␈↓¬        SAMEADEF:
␈↓ ↓H␈↓¬                ∀X Y.(SAMEA(X,Y) = ((CAR X) EEQ (CAR Y)) AAND SAMEFRINGEA(CDR X,CDR Y));
␈↓ ↓H␈↓¬        ETVSAMEA:
␈↓ ↓H␈↓¬                ∀XX YY. ISETV SAMEA(XX,YY);
␈↓ ↓H␈↓¬        GOPHERDEF:
␈↓ ↓H␈↓¬                ∀X.(GOPHER X = IF (ATOM CAR X) THEN X
␈↓ ↓H␈↓¬                                        ELSE GOPHER CONS(CAR CAR X,CONS(CDR CAR X, CDR X)));
␈↓ ↓H␈↓¬        THMDEF:
␈↓ ↓H␈↓¬                ∀X Y.(THM(X,Y)≡(ISTV SAMEFRINGEA(X,Y))∧
␈↓ ↓H␈↓¬                    (SAMEFRINGE(X,Y)≡X=Y∨((¬ATOM X∧¬ATOM Y)∧SAME(GOPHER X,GOPHER Y)))∧
␈↓ ↓H␈↓¬                    (SAMEFRINGE(X,Y)≡FRINGE X=FRINGE Y));
␈↓ ↓H␈↓¬        ;;
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ %vii


␈↓ ↓H␈↓α␈↓ βvSummary of Lemmas and Theorems to be proved.


␈↓ ↓H␈↓αAPPEND Lemmas

␈↓ ↓H␈↓¬        NIL_APPEND:     ∀U.(NNIL*U)=U
␈↓ ↓H␈↓¬        ISTOT_APPEND:   ∀U V.ISLIST (U*V)
␈↓ ↓H␈↓¬        NOTNUL_APPEND:  ∀U V.((¬NULL U∨¬NULL V)⊃¬NULL (U*V))
␈↓ ↓H␈↓¬        CAR_APPEND:     ∀U V.(¬NULL U⊃CAR (U*V)=CAR U)
␈↓ ↓H␈↓¬        CDR_APPEND:     ∀U V.(¬NULL U⊃CDR (U*V)=(CDR U*V))
␈↓ ↓H␈↓¬        ASSOC_APPEND:   ∀U V W.((U*V)*W)=(U*(V*W))

␈↓ ↓H␈↓αETV Lemmas

␈↓ ↓H␈↓¬        TVEEQ:          ∀X Y.(ISTV X EEQ Y)
␈↓ ↓H␈↓¬        EQEEQ:          ∀X Y.((X EEQ Y=TT)≡(X=Y))
␈↓ ↓H␈↓¬        TVOOR:          ∀P Q.(ISTV(P OOR Q))
␈↓ ↓H␈↓¬        TVAAND:         ∀P Q.(ISTV(P AAND Q))
␈↓ ↓H␈↓¬        EQOOR:          ∀P Q.((P OOR Q = TT)≡(P=TT ∨ Q=TT))
␈↓ ↓H␈↓¬        EQAAND:         ∀P Q.((P AAND Q = TT)≡(P=TT ∧ Q=TT))
␈↓ ↓H␈↓¬        TVNOTATM:       ∀X Y.((ISTV (NNOT AATOM X AAND NNOT AATOM Y)))
␈↓ ↓H␈↓¬        EQNOTATM:       ∀X Y.((((NNOT AATOM X AAND NNOT AATOM Y)= TT)≡(¬ATOM X∧¬ATOM Y)))
␈↓ ↓H␈↓¬        POORF:          ∀P.(P OOR FF=P)
␈↓ ↓H␈↓¬        FAANDQQ:        ∀QQ.(FF AAND QQ = FF)

␈↓ ↓H␈↓αFRINGE  GOPHER and SIZE Lemmas

␈↓ ↓H␈↓¬        GOOD_GOPHER:    ∀X.((¬ATOM X)⊃(ISSEXP GOPHER X∧ISSEXP CAR GOPHER X
␈↓ ↓H␈↓¬                                                ∧ISSEXP CDR GOPHER X))
␈↓ ↓H␈↓¬        ISTOT_FRINGE:   ∀X.(ISLIST FRINGE X∧¬NULL FRINGE X)
␈↓ ↓H␈↓¬        GOOD_FRINGE:    ∀X.(¬ATOM FRINGE X∧ISSEXP FRINGE X)
␈↓ ↓H␈↓¬        ISTOT_SIZE:     ∀X.NATNUM(SIZE X)
␈↓ ↓H␈↓¬        FRINGE_ATM:     ∀X Y.((ATOM X∨ATOM Y)⊃((FRINGE X=FRINGE Y)≡(X=Y)))
␈↓ ↓H␈↓¬        FRINGE_GOPHER:  ∀X.((¬ATOM X)⊃(CAR FRINGE X=CAR GOPHER X
␈↓ ↓H␈↓¬                                                ∧CDR FRINGE X=FRINGE CDR GOPHER X))
␈↓ ↓H␈↓¬        EQU_FRINGE:     ∀X Y.(X=Y∨FRINGE X=FRINGE Y≡FRINGE X=FRINGE Y)
␈↓ ↓H␈↓¬        SIZE_GOPHER:    ∀X Y.((¬ATOM X∧¬ATOM Y)
␈↓ ↓H␈↓¬                                ⊃((SIZE CDR GOPHER X+SIZE CDR GOPHER Y)<(SIZE X+SIZE Y)))

␈↓ ↓H␈↓αSamefringe Theorems

␈↓ ↓H␈↓¬        THM1:   ∀X Y. ISTV SAMEFRINGEA(X,Y)
␈↓ ↓H␈↓¬        THM2:   ∀X Y.(SAMEFRINGE(X,Y)=(X=Y)∨((¬ATOM X∧¬ATOM Y)∧SAME(GOPHER X,GOPHER Y)))
␈↓ ↓H␈↓¬        THM3:   ∀X Y.(SAMEFRINGE(X,Y)≡FRINGE X=FRINGE Y)
␈↓ ↓H␈↓viii␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓α␈↓ ∧nProof of properties of APPEND

␈↓ ↓H␈↓ε        ␈↓↓To␈α∞provide␈α∞a␈α∞better␈α∞introduction␈α∞to␈α∞FOL,␈α∂all␈α∞of␈α∞the␈α∞generated␈α∞proof␈α∞steps␈α∞are␈α∞given␈α∂for␈α∞the
␈↓ ↓H␈↓↓APPEND lemmas.␈↓ε


␈↓ ↓H␈↓α␈↓ ¬)Proving NIL_APPEND

␈↓ ↓H␈↓εSIMPLIFY ;
␈↓ ↓H␈↓ε␈↓¬1:   NULL NNIL  ␈↓ε
␈↓ ↓H␈↓εMONADIC         APPENDDEF,↑;
␈↓ ↓H␈↓ε␈↓¬NIL_APPEND: 2:  ∀U.(NNIL*U)=U␈↓ε


␈↓ ↓H␈↓α␈↓ ¬∀Proving ISTOT_APPEND

␈↓ ↓H␈↓ε␈↓α Induction axiom.␈↓ε
␈↓ ↓H␈↓ε∧I  LISTINDUCTION  [PHI←λU.∀V.ISLIST U*V];
␈↓ ↓H␈↓ε␈↓¬TOTAPP_IND: 3:  (∀U.(NULL U⊃∀V.ISLIST (U*V))∧∀U.((¬NULL U∧∀V.ISLIST (CDR U*V))⊃∀V.ISLIST (U*V)))
␈↓ ↓H␈↓¬                                        ⊃∀U V.ISLIST (U*V)␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε  ␈↓¬NULL U␈↓ε

␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬NULLU: 4:   NULL U  (4)␈↓ε
␈↓ ↓H␈↓εSIMPLIFY ;
␈↓ ↓H␈↓ε␈↓¬5:   ISLIST V  ␈↓ε
␈↓ ↓H␈↓εMONADIC         APPENDDEF ↑,NULLU;
␈↓ ↓H␈↓ε␈↓¬6:   ISLIST (U*V)  (4)␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ V;
␈↓ ↓H␈↓ε␈↓¬7:   ∀V.ISLIST (U*V)  (4)␈↓ε
␈↓ ↓H␈↓ε⊃I   NULLU⊃↑;
␈↓ ↓H␈↓ε␈↓¬8:   NULL U⊃∀V.ISLIST (U*V)  ␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ U;
␈↓ ↓H␈↓ε␈↓¬TOTAPP_NUL: 9:   ∀U.(NULL U⊃∀V.ISLIST (U*V))␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε  ␈↓¬¬NULL U␈↓ε

␈↓ ↓H␈↓ε␈↓αInduction hypothesis.␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬TOTAPP_HYP: 10:   ¬NULL U∧∀V.ISLIST (CDR U*V)  (10)␈↓ε
␈↓ ↓H␈↓εMONADIC         ↑,CONSDF1,CARDEF1,ATOMDF2;
␈↓ ↓H␈↓ε␈↓¬11:   ISLIST CONS(CAR U,CDR U*V)  (10)␈↓ε
␈↓ ↓H␈↓εMONADIC         APPENDDEF,TOTAPP_HYP,↑;
␈↓ ↓H␈↓ε␈↓¬12:   ISLIST (U*V)  (10)␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ V;
␈↓ ↓H␈↓ε␈↓¬13:   ∀V.ISLIST (U*V)  (10)␈↓ε
␈↓ ↓H␈↓ε⊃I   TOTAPP_HYP⊃↑;
␈↓ ↓H␈↓ε␈↓¬14:   (¬NULL U∧∀V.ISLIST (CDR U*V))⊃∀V.ISLIST (U*V)  ␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ U;
␈↓ ↓H␈↓ε␈↓¬15:   ∀U.((¬NULL U∧∀V.ISLIST (CDR U*V))⊃∀V.ISLIST (U*V))␈↓ε

␈↓ ↓H␈↓ε␈↓α Combine cases and apply induction axiom.␈↓ε
␈↓ ↓H␈↓εTAUT            TOTAPP_IND,TOTAPP_NUL,↑;
␈↓ ↓H␈↓ε␈↓¬ISTOT_APPEND: 16:   ∀U V.ISLIST (U*V)␈↓ε
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ .ix


␈↓ ↓H␈↓α␈↓ ¬αProving NOTNUL_APPEND


␈↓ ↓H␈↓ε␈↓αCase␈↓ε ␈↓¬¬NULL U␈↓ε

␈↓ ↓H␈↓εMONADIC         ATOMDF2,CARDEF1,CDRDEF3,CONSDF1,CONSDF3,ISTOT_APPEND;
␈↓ ↓H␈↓ε␈↓¬17:   ¬NULL U⊃¬NULL CONS(CAR U,CDR U*V)  ␈↓ε
␈↓ ↓H␈↓εMONADIC         ↑,APPENDDEF;
␈↓ ↓H␈↓ε␈↓¬18:   ¬NULL U⊃¬NULL (U*V)  ␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε ␈↓¬¬NULL V␈↓ε

␈↓ ↓H␈↓εMONADIC         APPENDDEF;
␈↓ ↓H␈↓ε␈↓¬19:   (NULL U∧¬NULL V)⊃¬NULL (U*V)  ␈↓ε
␈↓ ↓H␈↓εTAUT            ↑,↑↑;
␈↓ ↓H␈↓ε␈↓¬20:   (¬NULL U∨¬NULL V)⊃¬NULL (U*V)  ␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ U V;
␈↓ ↓H␈↓ε␈↓¬NOTNUL_APPEND: 21:   ∀U V.((¬NULL U∨¬NULL V)⊃¬NULL (U*V))␈↓ε


␈↓ ↓H␈↓α␈↓ ∧↔Proving CAR_APPEND and CDR_APPEND

␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬NOTNULU: 22:    ¬NULL U  (22)␈↓ε
␈↓ ↓H␈↓εMONADIC         APPENDDEF,NOTNULU;
␈↓ ↓H␈↓ε␈↓¬APPENDNOTNUL: 23:  (U*V)=CONS(CAR U,CDR U*V)  (22)␈↓ε

␈↓ ↓H␈↓αCAR part

␈↓ ↓H␈↓ε∀E   CARDEF2   CAR U,CDR U*V;
␈↓ ↓H␈↓ε␈↓¬24:   ISSEXP CAR U⊃(ISSEXP (CDR U*V)⊃CAR U=CAR CONS(CAR U,CDR U*V))  ␈↓ε
␈↓ ↓H␈↓εMONADIC         ↑,NOTNULU CARDEF1,CDRDEF3,ATOMDF2,SORTAX,ISTOT_APPEND;
␈↓ ↓H␈↓ε␈↓¬25:   CAR CONS(CAR U,CDR U*V)=CAR U  (22)␈↓ε
␈↓ ↓H␈↓εSUBST   APPENDNOTNUL IN ↑;
␈↓ ↓H␈↓ε␈↓¬26:   CAR (U*V)=CAR U  (22)␈↓ε
␈↓ ↓H␈↓ε⊃I   NOTNULU⊃↑;
␈↓ ↓H␈↓ε␈↓¬27:   ¬NULL U⊃CAR (U*V)=CAR U  ␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ U V;
␈↓ ↓H␈↓ε␈↓¬CAR_APPEND: 28:   ∀U V.(¬NULL U⊃CAR (U*V)=CAR U) ␈↓ε

␈↓ ↓H␈↓αCDR part

␈↓ ↓H␈↓ε∀E   CDRDEF2   CAR U,CDR U*V;
␈↓ ↓H␈↓ε␈↓¬29:   ISSEXP CAR U⊃(ISSEXP (CDR U*V)⊃(CDR U*V)=CDR CONS(CAR U,CDR U*V))  ␈↓ε
␈↓ ↓H␈↓εMONADIC         ↑,NOTNULU,CARDEF1,CDRDEF3,ATOMDF2,SORTAX,ISTOT_APPEND;
␈↓ ↓H␈↓ε␈↓¬30:   CDR CONS(CAR U,CDR U*V)=(CDR U*V)  (22)␈↓ε
␈↓ ↓H␈↓εSUBST   APPENDNOTNUL IN ↑;
␈↓ ↓H␈↓ε␈↓¬31:   CDR (U*V)=(CDR U*V)  (22)␈↓ε
␈↓ ↓H␈↓ε⊃I   NOTNULU⊃↑;
␈↓ ↓H␈↓ε␈↓¬32:   ¬NULL U⊃CDR (U*V)=(CDR U*V)  ␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ U V;
␈↓ ↓H␈↓ε␈↓¬CDR_APPEND: 33:   ∀U V.(¬NULL U⊃CDR (U*V)=(CDR U*V)) ␈↓ε
␈↓ ↓H␈↓x␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓α␈↓ ¬∪Proving ASSOC_APPEND


␈↓ ↓H␈↓αInduction axiom

␈↓ ↓H␈↓ε∧I   LISTINDUCTION   [PHI←λU.∀V W.((U*V)*W=U*(V*W))];
␈↓ ↓H␈↓ε␈↓¬ASSOC_IND: 34:        (∀U.(NULL U⊃∀V W.((U*V)*W)=(U*(V*W)))
␈↓ ↓H␈↓¬                        ∧∀U.((¬NULL U∧∀V W.((CDR U*V)*W)=(CDR U*(V*W)))⊃∀V W.((U*V)*W)=(U*(V*W))))
␈↓ ↓H␈↓¬                                ⊃∀U V W.((U*V)*W)=(U*(V*W))  ␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε ␈↓¬NULL U␈↓ε

␈↓ ↓H␈↓εMONADIC         APPENDDEF,NULLU;
␈↓ ↓H␈↓ε␈↓¬ASSOC1: 35:   (U*V)=V  (4)␈↓ε
␈↓ ↓H␈↓ε∀E   APPENDDEF   U,V*W;
␈↓ ↓H␈↓ε␈↓¬36:   ISLIST (V*W)⊃((NULL U⊃(U*(V*W))=(V*W))
␈↓ ↓H␈↓¬                        ∧(¬NULL U⊃(U*(V*W))=CONS(CAR U,CDR U*(V*W))))  ␈↓ε
␈↓ ↓H␈↓εMONADIC         ↑,ISTOT_APPEND,NULLU;
␈↓ ↓H␈↓ε␈↓¬ASSOC2: 37:   (V*W)=(U*(V*W))  (4)␈↓ε
␈↓ ↓H␈↓εTAUTEQ ;
␈↓ ↓H␈↓ε␈↓¬38:   ((U*V)*W)=((U*V)*W)  ␈↓ε
␈↓ ↓H␈↓εSUBSTR   ASSOC1 IN ↑ OCC 2;
␈↓ ↓H␈↓ε␈↓¬39:   ((U*V)*W)=(V*W)  (4)␈↓ε
␈↓ ↓H␈↓εSUBSTR   ASSOC2 IN ↑;
␈↓ ↓H␈↓ε␈↓¬40:   ((U*V)*W)=(U*(V*W))  (4)␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ V W;
␈↓ ↓H␈↓ε␈↓¬41:   ∀V W.((U*V)*W)=(U*(V*W))  (4)␈↓ε
␈↓ ↓H␈↓ε⊃I  NULLU⊃↑;
␈↓ ↓H␈↓ε␈↓¬42:   NULL U⊃∀V W.((U*V)*W)=(U*(V*W))  ␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ U;
␈↓ ↓H␈↓ε␈↓¬ASSOC_NUL: 43:   ∀U.(NULL U⊃∀V W.((U*V)*W)=(U*(V*W)))  ␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε ␈↓¬¬NULL U␈↓ε

␈↓ ↓H␈↓ε␈↓αInduction hypothesis␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬ASSOC_HYP: 44:   ¬NULL U∧∀V W.((CDR U*V)*W)=(CDR U*(V*W))  (44)␈↓ε

␈↓ ↓H␈↓αForm a chain of equalities.

␈↓ ↓H␈↓ε∀E   APPENDDEF   U*V,W;
␈↓ ↓H␈↓ε␈↓¬45:   ISLIST (U*V)⊃((NULL (U*V)⊃((U*V)*W)=W)
␈↓ ↓H␈↓¬                        ∧(¬NULL (U*V)⊃((U*V)*W)=CONS(CAR (U*V),CDR (U*V)*W))) ␈↓ε
␈↓ ↓H␈↓ε∀E   NOTNUL_APPEND   U,V;
␈↓ ↓H␈↓ε␈↓¬46:   (¬NULL U∨¬NULL V)⊃¬NULL (U*V)  ␈↓ε
␈↓ ↓H␈↓εMONADIC         ↑↑:↑,ASSOC_HYP,ISTOT_APPEND;
␈↓ ↓H␈↓ε␈↓¬ASSOC3: 47:   ((U*V)*W)=CONS(CAR (U*V),CDR (U*V)*W)  (44)␈↓ε
␈↓ ↓H␈↓εMONADIC         CAR_APPEND,ASSOC_HYP;
␈↓ ↓H␈↓ε␈↓¬ASSOC4: 48:   CAR (U*V)=CAR U  (44)␈↓ε
␈↓ ↓H␈↓εMONADIC         CDR_APPEND,ASSOC_HYP;
␈↓ ↓H␈↓ε␈↓¬ASSOC5: 49:   CDR (U*V)=(CDR U*V)  (44)␈↓ε
␈↓ ↓H␈↓εMONADIC         ASSOC_HYP;
␈↓ ↓H␈↓ε␈↓¬ASSOC6: 50:   ((CDR U*V)*W)=(CDR U*(V*W))  (44)␈↓ε
␈↓ ↓H␈↓ε∀E   APPENDDEF   U,V*W;
␈↓ ↓H␈↓ε␈↓¬51:   ISLIST (V*W)⊃((NULL U⊃(U*(V*W))=(V*W))
␈↓ ↓H␈↓¬                        ∧(¬NULL U⊃(U*(V*W))=CONS(CAR U,CDR U*(V*W))))  ␈↓ε
␈↓ ↓H␈↓εMONADIC         ↑,ASSOC_HYP,ISTOT_APPEND;
␈↓ ↓H␈↓ε␈↓¬ASSOC7: 52:   CONS(CAR U,CDR U*(V*W))=(U*(V*W))  (44)␈↓ε
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ .xi


␈↓ ↓H␈↓ε␈↓αTransform␈↓ε ␈↓¬(U*V)*W␈↓ε ␈↓αinto␈↓ε ␈↓¬U*(V*W)␈↓ε ␈↓αusing the equalities.␈↓ε

␈↓ ↓H␈↓εREWRITE   (U*V)*W  BY  {ASSOC3,ASSOC4,ASSOC5,ASSOC6,ASSOC7};
␈↓ ↓H␈↓ε␈↓¬53:   ((U*V)*W)=(U*(V*W))  (44)␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ V W;
␈↓ ↓H␈↓ε␈↓¬54:   ∀V W.((U*V)*W)=(U*(V*W))  (44)␈↓ε
␈↓ ↓H␈↓ε⊃I   ASSOC_HYP⊃↑;
␈↓ ↓H␈↓ε␈↓¬55:   (¬NULL U∧∀V W.((CDR U*V)*W)=(CDR U*(V*W)))⊃∀V W.((U*V)*W)=(U*(V*W))  ␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ U;
␈↓ ↓H␈↓ε␈↓¬56:   ∀U.((¬NULL U∧∀V W.((CDR U*V)*W)=(CDR U*(V*W)))⊃∀V W.((U*V)*W)=(U*(V*W)))  ␈↓ε

␈↓ ↓H␈↓αCombine cases and appply induction axiom.

␈↓ ↓H␈↓εTAUT            ASSOC_IND,ASSOC_NUL,↑;
␈↓ ↓H␈↓ε␈↓¬ASSOC_APPEND: 57:   ∀U V W.((U*V)*W)=(U*(V*W))  ␈↓ε
␈↓ ↓H␈↓xii␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓α␈↓ ¬oETV lemmas

␈↓ ↓H␈↓εSIMPLIFY  ;
␈↓ ↓H␈↓ε␈↓¬TVNESS: 1:  ISTV TT∧(ISTV FF∧ISTV Q)  ␈↓ε

␈↓ ↓H␈↓α␈↓ ¬↓Proving TVEEQ and EQEEQ

␈↓ ↓H␈↓ε∀E   EQUDEF   X Y;    SIMPLIFY  ;
␈↓ ↓H␈↓ε␈↓¬3:  (X EEQ Y)=IF X=Y THEN TT ELSE FF  ␈↓ε
␈↓ ↓H␈↓εTAUTEQ   ISTV (X EEQ Y)   ↑,TVNESS;    ∀I   ↑ X Y;
␈↓ ↓H␈↓ε␈↓¬TVEEQ: 5:   ∀X Y.ISTV (X EEQ Y)  ␈↓ε
␈↓ ↓H␈↓εTAUTEQ   (X EEQ Y) =TT ≡ X = Y   ↑↑↑,TVSET;    ∀I   ↑ X Y;
␈↓ ↓H␈↓ε␈↓¬EQEEQ: 7:   ∀X Y.((X EEQ Y)=TT≡X=Y)  ␈↓ε

␈↓ ↓H␈↓α␈↓ ∧eProving TVAAND and EQAAND

␈↓ ↓H␈↓εMONADIC          ANDDEF,TVEXT,TVSET;
␈↓ ↓H␈↓ε␈↓¬8:   (P AAND Q)=IF P=TT THEN Q ELSE FF  ␈↓ε
␈↓ ↓H␈↓εTAUTEQ   ISTV (P AAND Q)   ↑,TVNESS;    ∀I   ↑ P Q;
␈↓ ↓H␈↓ε␈↓¬TVAAND: 10:   ∀P Q.ISTV (P AAND Q)  ␈↓ε
␈↓ ↓H␈↓εTAUTEQ   (P AAND Q) = TT ≡ P=TT ∧ Q=TT   ↑↑↑,TVSET;    ∀I   ↑ P Q;
␈↓ ↓H␈↓ε␈↓¬EQAAND: 12:   ∀P Q.((P AAND Q)=TT≡(P=TT∧Q=TT))  ␈↓ε

␈↓ ↓H␈↓α␈↓ ∧zProving TVOOR and EQOOR

␈↓ ↓H␈↓εMONADIC         ORDEF,TVEXT,TVSET;
␈↓ ↓H␈↓ε␈↓¬13:   (P OOR Q)=IF P=TT THEN TT ELSE Q  ␈↓ε
␈↓ ↓H␈↓εTAUTEQ   ISTV (P OOR Q)   ↑,TVNESS;    ∀I   ↑ P Q;
␈↓ ↓H␈↓ε␈↓¬TVOOR: 15:   ∀P Q.ISTV (P OOR Q)  ␈↓ε
␈↓ ↓H␈↓εTAUTEQ   (P OOR Q) = TT ≡ P=TT ∨ Q=TT    ↑↑↑,TVSET;    ∀I   ↑ P Q;
␈↓ ↓H␈↓ε␈↓¬EQOOR: 17:   ∀P Q.((P OOR Q)=TT≡(P=TT∨Q=TT))  ␈↓ε

␈↓ ↓H␈↓α␈↓ ∧4Proving TVNOTATM and EQNOTATM

␈↓ ↓H␈↓ε∀E   ATDEF   X;    SIMPLIFY ;
␈↓ ↓H␈↓ε␈↓¬AATOMX: 19:   AATOM X=IF ATOM X THEN TT ELSE FF  ␈↓ε
␈↓ ↓H␈↓εMONADIC         NOTDEF,TVEXT,TVSET;
␈↓ ↓H␈↓ε␈↓¬NNOTP: 20:   NNOT P=IF P=TT THEN FF ELSE TT  ␈↓ε

␈↓ ↓H␈↓α␈↓ β:Proving TVNNOT TVAATOM EQNNOT and EQAATOM

␈↓ ↓H␈↓εTAUTEQ   ISTV NNOT P   NNOTP,TVNESS;    ∀I   ↑ P;
␈↓ ↓H␈↓ε␈↓¬TVNNOT: 22:   ∀P.ISTV NNOT P  ␈↓ε
␈↓ ↓H␈↓εTAUTEQ   NNOT P = TT ≡ ¬(P = TT)   NNOTP,TVSET;    ∀I   ↑ P;
␈↓ ↓H␈↓ε␈↓¬EQNNOT: 24:   ∀P.(NNOT P=TT≡¬(P=TT))  ␈↓ε
␈↓ ↓H␈↓εTAUTEQ   ISTV AATOM X   AATOMX,TVNESS;    ∀I   ↑ X;
␈↓ ↓H␈↓ε␈↓¬TVAATOM: 26:   ∀X.ISTV AATOM X  ␈↓ε
␈↓ ↓H␈↓εTAUTEQ   AATOM X = TT ≡ ATOM X   AATOMX,TVSET;    ∀I   ↑ X;
␈↓ ↓H␈↓ε␈↓¬EQAATOM: 28:   ∀X.(AATOM X=TT≡ATOM X)  ␈↓ε
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ ≤xiii


␈↓ ↓H␈↓α␈↓ ∧4Proving TVNOTATM and EQNOTATM

␈↓ ↓H␈↓εMONADIC         TVAATOM,TVNNOT;
␈↓ ↓H␈↓ε␈↓¬29:   ∀X.ISTV NNOT AATOM X  ␈↓ε
␈↓ ↓H␈↓εMONADIC         TVAAND,↑;
␈↓ ↓H␈↓ε␈↓¬TVNOTATM: 30:   ∀X Y.ISTV (NNOT AATOM X AAND NNOT AATOM Y)  ␈↓ε
␈↓ ↓H␈↓εMONADIC         EQNNOT, EQAATOM, TVAATOM;
␈↓ ↓H␈↓ε␈↓¬31:   ∀X.(NNOT AATOM X=TT≡¬ATOM X)  ␈↓ε
␈↓ ↓H␈↓ε∀E   EQAAND   NNOT AATOM X, NNOT AATOM Y;
␈↓ ↓H␈↓εMONADIC         ↑,↑↑,↑↑↑↑;
␈↓ ↓H␈↓ε␈↓¬33:   (NNOT AATOM X AAND NNOT AATOM Y)=TT≡(¬ATOM X∧¬ATOM Y)  ␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ X Y;
␈↓ ↓H␈↓ε␈↓¬EQNOTATM: 34:   ∀X Y.((NNOT AATOM X AAND NNOT AATOM Y)=TT≡(¬ATOM X∧¬ATOM Y))  ␈↓ε

␈↓ ↓H␈↓α␈↓ ∧gProving POORF and FAANDQQ

␈↓ ↓H␈↓εMONADIC         ORDEF,TVEXT,TVSET;
␈↓ ↓H␈↓ε␈↓¬POORF: 35:   ∀P.(P OOR FF)=P  ␈↓ε
␈↓ ↓H␈↓εMONADIC         ANDDEF,TVSET;
␈↓ ↓H␈↓ε␈↓¬FAANDQQ: 36:   ∀QQ.(FF AAND QQ)=FF  ␈↓ε
␈↓ ↓H␈↓xiv␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓α␈↓ ∧↔Lemmas about GOPHER, FRINGE and SIZE



␈↓ ↓H␈↓αPreviously proved results

␈↓ ↓H␈↓ε␈↓¬AXIOM ISTOT_APPEND: ∀U V.ISLIST(U*V);;
␈↓ ↓H␈↓¬AXIOM NOTNUL_APPEND: ∀U V.((¬NULL U∨¬NULL V)⊃¬NULL(U*V));;
␈↓ ↓H␈↓¬AXIOM ASSOC_APPEND: ∀U V W.((U*V)*W=U*(V*W));;
␈↓ ↓H␈↓¬AXIOM CDR_APPEND: ∀U V.(¬NULL U⊃CDR (U*V)=(CDR U*V));;
␈↓ ↓H␈↓¬AXIOM CAR_APPEND: ∀U V.(¬NULL U⊃CAR (U*V)=CAR U);;␈↓ε

␈↓ ↓H␈↓αBasic definitions and assumptions

␈↓ ↓H␈↓εSIMPLIFY ;
␈↓ ↓H␈↓ε␈↓¬NULNIL: 1:   NULL NNIL  ␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬XISATM: 2:   ATOM X  (2)␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬XISNTATM: 3:   ¬ATOM X  (3)␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬XISY: 4:   X=Y  (4)␈↓ε
␈↓ ↓H␈↓εMONADIC         XISNTATM,CONSDF4;
␈↓ ↓H␈↓ε␈↓¬MAKEX: 5:   CONS(CAR X,CDR X)=X  (3)␈↓ε


␈↓ ↓H␈↓α␈↓ ¬⊃Proof of GOOD_GOPHER


␈↓ ↓H␈↓ε␈↓αFirst prove desired properties for␈↓ε  ␈↓¬GOPHER CONS(X, Y)␈↓ε

␈↓ ↓H␈↓εREWRITE   GOPHER CONS(X,Y) BY {GOPHERDEF,CARCONS,CDRCONS};
␈↓ ↓H␈↓ε␈↓¬GOPHER_CONS: 6:  GOPHER CONS(X,Y)=IF ATOM X THEN CONS(X,Y)
␈↓ ↓H␈↓¬                                        ELSE GOPHER CONS(CAR X,CONS(CDR X,Y))␈↓ε
␈↓ ↓H␈↓εTAUTEQ          ↑,XISATM;
␈↓ ↓H␈↓ε␈↓¬GOPHER_CONS_ATM: 7:   CONS(X,Y)=GOPHER CONS(X,Y)  (2)␈↓ε

␈↓ ↓H␈↓ε␈↓αInduction axiom␈↓ε
␈↓ ↓H␈↓ε∧I  SEXPINDUCTION  [PHI←λX.∀Y.(ISSEXP GOPHER CONS(X,Y)∧¬ATOM GOPHER CONS(X,Y))];
␈↓ ↓H␈↓ε␈↓¬GOODGO_IND: 8:   (∀X.(ATOM X⊃∀Y.(ISSEXP GOPHER CONS(X,Y)∧¬ATOM GOPHER CONS(X,Y)))
␈↓ ↓H␈↓¬        ∧∀X.((¬ATOM X∧(∀Y.(ISSEXP GOPHER CONS(CAR X,Y)∧¬ATOM GOPHER CONS(CAR X,Y))
␈↓ ↓H␈↓¬                      ∧∀Y.(ISSEXP GOPHER CONS(CDR X,Y)∧¬ATOM GOPHER CONS(CDR X,Y))))
␈↓ ↓H␈↓¬                ⊃∀Y.(ISSEXP GOPHER CONS(X,Y)∧¬ATOM GOPHER CONS(X,Y))))
␈↓ ↓H␈↓¬        ⊃∀X Y.(ISSEXP GOPHER CONS(X,Y)∧¬ATOM GOPHER CONS(X,Y))  ␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε  ␈↓¬ATOM X␈↓ε

␈↓ ↓H␈↓εMONADIC         GOPHER_CONS,XISATM,CONSDF2,CONSDF3;
␈↓ ↓H␈↓ε␈↓¬9:   ISSEXP GOPHER CONS(X,Y)∧¬ATOM GOPHER CONS(X,Y)  (2)␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ Y;    ⊃I  XISATM⊃↑;    ∀I   ↑ X;
␈↓ ↓H␈↓ε␈↓¬GOODGO_ATM: 12:   ∀X.(ATOM X⊃∀Y.(ISSEXP GOPHER CONS(X,Y)∧¬ATOM GOPHER CONS(X,Y)))␈↓ε
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ &xv


␈↓ ↓H␈↓ε␈↓αCase␈↓ε  ␈↓¬¬ATOM X␈↓ε

␈↓ ↓H␈↓ε␈↓αInduction hypothesis␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬GOODGOHYP: 13:   ¬ATOM X∧(∀Y.(ISSEXP GOPHER CONS(CAR X,Y)∧¬ATOM GOPHER CONS(CAR X,Y))
␈↓ ↓H␈↓¬                        ∧∀Y.(ISSEXP GOPHER CONS(CDR X,Y)∧¬ATOM GOPHER CONS(CDR X,Y)))  (13)␈↓ε
␈↓ ↓H␈↓εMONADIC         GOPHER_CONS,↑;
␈↓ ↓H␈↓ε␈↓¬14:   ISSEXP GOPHER CONS(X,Y)∧¬ATOM GOPHER CONS(X,Y)  (13)␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ Y;   ⊃I   GOODGOHYP⊃↑;    ∀I   ↑ X;
␈↓ ↓H␈↓ε␈↓¬GOODGO_NOTATM: 17:  ∀X.((¬ATOM X
␈↓ ↓H␈↓¬                        ∧(∀Y.(ISSEXP GOPHER CONS(CAR  X,Y)∧¬ATOM GOPHER CONS(CAR X,Y))
␈↓ ↓H␈↓¬                        ∧∀Y.(ISSEXP GOPHER CONS(CDR X,Y)∧¬ATOM GOPHER CONS(CDR X,Y))))
␈↓ ↓H␈↓¬                        ⊃∀Y.(ISSEXP GOPHER CONS(X,Y)∧¬ATOM GOPHER CONS(X,Y)))  ␈↓ε

␈↓ ↓H␈↓ε␈↓αApply induction axiom␈↓ε
␈↓ ↓H␈↓εTAUT            GOODGO_IND,GOODGO_ATM,GOODGO_NOTATM;
␈↓ ↓H␈↓ε␈↓¬18:   ∀X Y.(ISSEXP GOPHER CONS(X,Y)∧¬ATOM GOPHER CONS(X,Y))  ␈↓ε

␈↓ ↓H␈↓ε␈↓αNow use MAKEX to replace␈↓ε ␈↓¬CONS(X,Y)␈↓ε ␈↓αby␈↓ε ␈↓¬X␈↓ε

␈↓ ↓H␈↓ε∀E  ↑   CAR X,CDR X;   SUBSTR  MAKEX IN ↑;    MONADIC           ↑,XISNTATM,CARDEF1,CDRDEF1;
␈↓ ↓H␈↓ε␈↓¬21:   ISSEXP GOPHER X∧(ISSEXP CAR GOPHER X∧ISSEXP CDR GOPHER X)  (3)␈↓ε
␈↓ ↓H␈↓ε⊃I   XISNTATM⊃↑;    ∀I   ↑ X;
␈↓ ↓H␈↓ε␈↓¬GOOD_GOPHER: 23:   ∀X.(¬ATOM X⊃(ISSEXP GOPHER X∧(ISSEXP CAR GOPHER X
␈↓ ↓H␈↓¬                                                        ∧ISSEXP CDR GOPHER X)))␈↓ε


␈↓ ↓H␈↓α␈↓ ∧¬Proving ISTOT_FRINGE and GOOD_FRINGE

␈↓ ↓H␈↓ε␈↓αInduction axiom␈↓ε
␈↓ ↓H␈↓ε∧I   SEXPINDUCTION   [PHI←λX.(ISLIST FRINGE X∧¬NULL FRINGE X)];
␈↓ ↓H␈↓ε␈↓¬TOTFR_IND: 24:   (∀X.(ATOM X⊃(ISLIST FRINGE X∧¬NULL FRINGE X))
␈↓ ↓H␈↓¬                ∧∀X.((¬ATOM X∧((ISLIST FRINGE CAR X∧¬NULL FRINGE CAR X)
␈↓ ↓H␈↓¬                                ∧(ISLIST FRINGE CDR X∧¬NULL FRINGE CDR X)))
␈↓ ↓H␈↓¬                        ⊃(ISLIST FRINGE X∧¬NULL FRINGE X)))
␈↓ ↓H␈↓¬                ⊃∀X.(ISLIST FRINGE X∧¬NULL FRINGE X)  ␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε ␈↓¬ATOM X␈↓ε

␈↓ ↓H␈↓εMONADIC         FRINGEDEF,CONSDF1,CONSDF3,ATOMDF2;
␈↓ ↓H␈↓ε␈↓¬TOTFR_NUL: 25:   ∀X.(ATOM X⊃(ISLIST FRINGE X∧¬NULL FRINGE X))  ␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε ␈↓¬¬ATOM X␈↓ε

␈↓ ↓H␈↓ε∀E   ISTOT_APPEND   FRINGE CAR X,FRINGE CDR X;
␈↓ ↓H␈↓ε∀E   NOTNUL_APPEND  FRINGE CAR X,FRINGE CDR X;
␈↓ ↓H␈↓εMONADIC         FRINGEDEF,↑↑:↑;    ∀I   ↑ X;
␈↓ ↓H␈↓ε␈↓¬29:   ∀X.((¬ATOM X∧((ISLIST FRINGE CAR X∧¬NULL FRINGE CAR X)
␈↓ ↓H␈↓¬                        ∧(ISLIST FRINGE CDR X∧¬NULL FRINGE CDR X)))
␈↓ ↓H␈↓¬                ⊃(ISLIST FRINGE X∧¬NULL FRINGE X))  ␈↓ε
␈↓ ↓H␈↓εTAUT            TOTFR_IND,TOTFR_NUL,↑;
␈↓ ↓H␈↓ε␈↓¬ISTOT_FRINGE: 30:   ∀X.(ISLIST FRINGE X∧¬NULL FRINGE X)  ␈↓ε
␈↓ ↓H␈↓εMONADIC         ↑,SORTAX,ATOMDF2;
␈↓ ↓H␈↓ε␈↓¬GOOD_FRINGE: 31:   ∀X.(ISSEXP FRINGE X∧¬ATOM FRINGE X)  ␈↓ε
␈↓ ↓H␈↓xvi␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓α␈↓ ¬2Proving ISTOT_SIZE

␈↓ ↓H␈↓ε␈↓αInduction axiom␈↓ε
␈↓ ↓H␈↓ε∧I  SEXPINDUCTION  [PHI←λX.NATNUM(SIZE X)];
␈↓ ↓H␈↓ε␈↓¬TOTSIZE_IND: 32:   (∀X.(ATOM X⊃NATNUM(SIZE X))
␈↓ ↓H␈↓¬                ∧∀X.((¬ATOM X∧(NATNUM(SIZE CAR X)∧NATNUM(SIZE CDR X)))⊃NATNUM(SIZE X)))
␈↓ ↓H␈↓¬                ⊃∀X.NATNUM(SIZE X)  ␈↓ε

␈↓ ↓H␈↓εSIMPLIFY   NATNUM(1);    MONADIC                ↑,SIZEDEF;
␈↓ ↓H␈↓ε␈↓¬TOTSIZE_ATM: 34:   ∀X.(ATOM X⊃NATNUM(SIZE X))  ␈↓ε
␈↓ ↓H␈↓ε∀E  ISTOT_PLUS  SIZE CAR X,SIZE CDR X;    MONADIC               ↑,SIZEDEF;    ∀I   ↑ X;
␈↓ ↓H␈↓ε␈↓¬37:   ∀X.((¬ATOM X∧(NATNUM(SIZE CAR X)∧NATNUM(SIZE CDR X)))⊃NATNUM(SIZE X))  ␈↓ε
␈↓ ↓H␈↓εTAUT            TOTSIZE_IND,TOTSIZE_ATM,↑;
␈↓ ↓H␈↓ε␈↓¬ISTOT_SIZE: 38:   ∀X.NATNUM(SIZE X)  ␈↓ε


␈↓ ↓H␈↓α␈↓ ¬&Proving FRINGE_ATM


␈↓ ↓H␈↓ε␈↓αCase␈↓ε ␈↓¬ATOM X ∧ ATOM Y␈↓ε

␈↓ ↓H␈↓εMONADIC         FRINGEDEF;
␈↓ ↓H␈↓ε␈↓¬39:   (ATOM X∧ATOM Y)⊃(FRINGE X=CONS(X,NNIL)∧FRINGE Y=CONS(Y,NNIL))  ␈↓ε
␈↓ ↓H␈↓ε∀E   EQSEXP   CONS(X,NNIL),CONS(Y,NNIL);    MONADIC             ↑↑:↑,CARDEF2,CDRDEF2,CONSDF3;
␈↓ ↓H␈↓ε␈↓¬FRATM: 41:   (ATOM X∧ATOM Y)⊃(FRINGE X=FRINGE Y≡X=Y)  ␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε ␈↓¬ATOM X ∧ ¬ATOM Y␈↓ε

␈↓ ↓H␈↓ε␈↓αShow␈↓ε   ␈↓¬¬NULL CDR (FRINGE CAR Y * FRINGE CDR Y)␈↓ε
␈↓ ↓H␈↓ε∀E CDR_APPEND FRINGE CAR Y,FRINGE CDR Y;
␈↓ ↓H␈↓ε∀E NOTNUL_APPEND CDR FRINGE CAR Y,FRINGE CDR Y;
␈↓ ↓H␈↓εMONADIC         CARDEF1,CDRDEF1,ISTOT_FRINGE,CDRDEF3;
␈↓ ↓H␈↓ε␈↓¬44:   ¬ATOM Y⊃(ISLIST FRINGE CAR Y∧(¬NULL FRINGE CAR Y
␈↓ ↓H␈↓¬                ∧(ISLIST FRINGE CDR Y∧(¬NULL FRINGE CDR Y∧ISLIST CDR FRINGE CAR Y))))  ␈↓ε
␈↓ ↓H␈↓εTAUTEQ          ↑↑↑:↑;
␈↓ ↓H␈↓ε␈↓¬45:   ¬ATOM Y⊃¬NULL CDR (FRINGE CAR Y*FRINGE CDR Y)  ␈↓ε

␈↓ ↓H␈↓ε␈↓αNow combine this with EQSEXP to show␈↓ε  ␈↓¬FRINGE X ≠ FRINGE Y␈↓ε
␈↓ ↓H␈↓ε∀E EQSEXP CONS(X,NNIL) , FRINGE CAR Y*FRINGE CDR Y;
␈↓ ↓H␈↓εMONADIC         ATOMDF3,CDRDEF2,CONSDF3;
␈↓ ↓H␈↓ε␈↓¬47:   NULL CDR CONS(X,NNIL)  ␈↓ε
␈↓ ↓H␈↓εMONADIC         FRINGEDEF;
␈↓ ↓H␈↓ε␈↓¬48:   (ATOM X∧¬ATOM Y)⊃(FRINGE X=CONS(X,NNIL)∧FRINGE Y=(FRINGE CAR Y*FRINGE CDR Y))  ␈↓ε
␈↓ ↓H␈↓εMONADIC         ↑↑↑↑:↑,GOOD_FRINGE,CONSDF3;
␈↓ ↓H␈↓ε␈↓¬49:   (ATOM X∧¬ATOM Y)⊃(FRINGE X=FRINGE Y≡X=Y)  ␈↓ε

␈↓ ↓H␈↓αExchange X and Y and combine the three cases.

␈↓ ↓H␈↓ε∀I   ↑ X Y;    ∀E   ↑ Y X;   TAUTEQ     FRATM,↑↑↑:↑;    ∀I   ↑ X Y;
␈↓ ↓H␈↓ε␈↓¬FRINGE_ATM: 53:   ∀X Y.((ATOM X∨ATOM Y)⊃(FRINGE X=FRINGE Y≡X=Y))  ␈↓ε
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ ∀xvii


␈↓ ↓H␈↓α␈↓ ¬λProving FRINGE_GOPHER


␈↓ ↓H␈↓ε␈↓αFirst prove the desired properties for argument␈↓ε  ␈↓¬(CONS(X,Y))␈↓ε

␈↓ ↓H␈↓ε␈↓αInduction axiom␈↓ε
␈↓ ↓H␈↓ε∧I  SEXPINDUCTION  [PHI←λX.∀Y.(CAR FRINGE CONS(X,Y)=CAR GOPHER CONS(X,Y)
␈↓ ↓H␈↓ε                                ∧CDR FRINGE CONS(X,Y)=FRINGE CDR GOPHER CONS(X,Y))];
␈↓ ↓H␈↓ε␈↓¬FRGO_IND: 54:   (∀X.(ATOM X⊃∀Y.(CAR FRINGE CONS(X,Y)=CAR GOPHER CONS(X,Y)
␈↓ ↓H␈↓¬                                ∧CDR FRINGE CONS(X,Y)=FRINGE CDR GOPHER CONS(X,Y)))
␈↓ ↓H␈↓¬        ∧∀X.((¬ATOM X∧(∀Y.(CAR FRINGE CONS(CAR X,Y)=CAR GOPHER CONS(CAR X,Y)
␈↓ ↓H␈↓¬                        ∧CDR FRINGE CONS(CAR X,Y)=FRINGE CDR GOPHER CONS(CAR X,Y))
␈↓ ↓H␈↓¬                ∧∀Y.(CAR FRINGE CONS(CDR X,Y)=CAR GOPHER CONS(CDR X,Y)
␈↓ ↓H␈↓¬                        ∧CDR FRINGE CONS(CDR X,Y)=FRINGE CDR GOPHER CONS(CDR X,Y))))
␈↓ ↓H␈↓¬                ⊃∀Y.(CAR FRINGE CONS(X,Y)=CAR GOPHER CONS(X,Y)
␈↓ ↓H␈↓¬                        ∧CDR FRINGE CONS(X,Y)=FRINGE CDR GOPHER CONS(X,Y))))
␈↓ ↓H␈↓¬        ⊃∀X Y.(CAR FRINGE CONS(X,Y)=CAR GOPHER CONS(X,Y)
␈↓ ↓H␈↓¬                ∧CDR FRINGE CONS(X,Y)=FRINGE CDR GOPHER CONS(X,Y))  ␈↓ε

␈↓ ↓H␈↓αSpecial case function definitions for FRINGE

␈↓ ↓H␈↓εMONADIC         FRINGEDEF,CONSDF3;
␈↓ ↓H␈↓ε␈↓¬55:   FRINGE CONS(X,Y)=(FRINGE CAR CONS(X,Y)*FRINGE CDR CONS(X,Y))  ␈↓ε
␈↓ ↓H␈↓εREWRITE   FRINGE CONS(X,Y) BY {↑,CARCONS,CDRCONS};
␈↓ ↓H␈↓ε␈↓¬FRINGE_CONSXY: 56:   FRINGE CONS(X,Y)=(FRINGE X*FRINGE Y)  ␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ X Y;
␈↓ ↓H␈↓ε␈↓¬FRINGE_CONS: 57:   ∀X Y.FRINGE CONS(X,Y)=(FRINGE X*FRINGE Y)  ␈↓ε
␈↓ ↓H␈↓εMONADIC         FRINGEDEF,XISATM;
␈↓ ↓H␈↓ε␈↓¬FRINGEATMX: 58:   FRINGE X=CONS(X,NNIL)  (2)␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε  ␈↓¬ATOM X␈↓ε

␈↓ ↓H␈↓ε␈↓αCAR part.  Prove by a chain of eqialities.␈↓ε
␈↓ ↓H␈↓ε∀E   CAR_APPEND   FRINGE X,FRINGE Y;   MONADIC    ↑,ISTOT_FRINGE;
␈↓ ↓H␈↓ε␈↓¬60:   CAR (FRINGE X*FRINGE Y)=CAR FRINGE X  ␈↓ε
␈↓ ↓H␈↓εMONADIC         CARDEF2;
␈↓ ↓H␈↓ε␈↓¬61:   CAR CONS(X,NNIL)=CAR CONS(X,Y)  ␈↓ε
␈↓ ↓H␈↓εSUBST   FRINGE_CONSXY IN ↑↑;    SUBSTR   FRINGEATMX IN ↑;
␈↓ ↓H␈↓εSUBSTR   ↑↑↑ IN ↑;    SUBSTR   GOPHER_CONS_ATM IN ↑ OCC 2;
␈↓ ↓H␈↓ε␈↓¬CARFRGO: 65:   CAR FRINGE CONS(X,Y)=CAR GOPHER CONS(X,Y)  (2)␈↓ε

␈↓ ↓H␈↓ε␈↓αCDR part.  Prove by a chain of equalities.␈↓ε
␈↓ ↓H␈↓ε∀E   CDR_APPEND   FRINGE X, FRINGE Y;    MONADIC    ↑,ISTOT_FRINGE;
␈↓ ↓H␈↓ε␈↓¬67:   CDR (FRINGE X*FRINGE Y)=(CDR FRINGE X*FRINGE Y)  ␈↓ε
␈↓ ↓H␈↓ε∀E   APPENDDEF   NNIL FRINGE Y;    MONADIC    ↑,NULNIL,ISTOT_FRINGE;
␈↓ ↓H␈↓ε␈↓¬69:   (NNIL*FRINGE Y)=FRINGE Y  ␈↓ε
␈↓ ↓H␈↓εSUBST   FRINGE_CONSXY IN ↑↑↑;    SUBSTR   FRINGEATMX IN ↑;
␈↓ ↓H␈↓ε␈↓¬71:   CDR FRINGE CONS(X,Y)=(CDR CONS(X,NNIL)*FRINGE Y)  (2)␈↓ε
␈↓ ↓H␈↓ε∀E   CDRCONS X NNIL;   SUBSTR   ↑ IN ↑↑;    SUBSTR   ↑↑↑↑↑ IN ↑;
␈↓ ↓H␈↓ε␈↓¬74:   CDR FRINGE CONS(X,Y)=FRINGE Y  (2)␈↓ε
␈↓ ↓H␈↓ε∀E   CDRDEF2 X Y;    SUBSTR   ↑ IN ↑↑ OCC 2;
␈↓ ↓H␈↓ε␈↓¬76:   CDR FRINGE CONS(X,Y)=FRINGE CDR CONS(X,Y)  (2)␈↓ε
␈↓ ↓H␈↓εSUBSTR   GOPHER_CONS_ATM IN ↑ OCC 2;
␈↓ ↓H␈↓ε␈↓¬77:   CDR FRINGE CONS(X,Y)=FRINGE CDR GOPHER CONS(X,Y)  (2)␈↓ε

␈↓ ↓H␈↓ε␈↓αCombine CAR and CDR parts␈↓ε
␈↓ ↓H␈↓ε∧I   CARFRGO ↑;     ∀I  ↑ Y;    ⊃I   XISATM⊃↑;    ∀I   ↑ X;
␈↓ ↓H␈↓ε␈↓¬FRGO_ATM: 81:   ∀X.(ATOM X⊃∀Y.(CAR FRINGE CONS(X,Y)=CAR GOPHER CONS(X,Y)
␈↓ ↓H␈↓¬                                ∧CDR FRINGE CONS(X,Y)=FRINGE CDR GOPHER CONS(X,Y)))  ␈↓ε
␈↓ ↓H␈↓xviii␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓ε␈↓αCase␈↓ε  ␈↓¬¬ATOM X␈↓ε

␈↓ ↓H␈↓ε␈↓αInduction hypothesis␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬FRGO_HYP: 82:   ¬ATOM X∧(∀Y.(CAR FRINGE CONS(CAR X,Y)=CAR GOPHER CONS(CAR X,Y)
␈↓ ↓H␈↓¬                                ∧CDR FRINGE CONS(CAR X,Y)=FRINGE CDR GOPHER CONS(CAR X,Y))
␈↓ ↓H␈↓¬                        ∧∀Y.(CAR FRINGE CONS(CDR X,Y)=CAR GOPHER CONS(CDR X,Y)
␈↓ ↓H␈↓¬                                ∧CDR FRINGE CONS(CDR X,Y)=FRINGE CDR GOPHER CONS(CDR X,Y)))  (82)␈↓ε

␈↓ ↓H␈↓ε␈↓αProve␈↓ε  ␈↓¬FRINGE CONS(X,Y)=FRINGE CONS(CAR X,CONS(CDR X,Y))␈↓ε  ␈↓αby a chain of equalities␈↓ε

␈↓ ↓H␈↓εMONADIC         FRINGEDEF,FRGO_HYP;
␈↓ ↓H␈↓ε␈↓¬FRGO1: 83:   FRINGE X=(FRINGE CAR X*FRINGE CDR X)  (82)␈↓ε
␈↓ ↓H␈↓ε∀E   ASSOC_APPEND   FRINGE CAR X,FRINGE CDR X,FRINGE Y;
␈↓ ↓H␈↓εMONADIC         ↑,CARDEF1,CDRDEF1,ISTOT_FRINGE,FRGO_HYP;
␈↓ ↓H␈↓ε␈↓¬FRGO2: 85:   ((FRINGE CAR X*FRINGE CDR X)*FRINGE Y)
␈↓ ↓H␈↓¬                =(FRINGE CAR X*(FRINGE CDR X*FRINGE Y))  (82)␈↓ε
␈↓ ↓H␈↓ε∀E   FRINGE_CONS   CDR X Y;    MONADIC    ↑,CDRDEF1,FRGO_HYP;
␈↓ ↓H␈↓ε␈↓¬FRGO3: 87:   (FRINGE CDR X*FRINGE Y)=FRINGE CONS(CDR X,Y)  (82)␈↓ε
␈↓ ↓H␈↓ε∀E   FRINGE_CONS   CAR X, CONS(CDR X,Y);
␈↓ ↓H␈↓εMONADIC         ↑,CARDEF1,FRGO_HYP,GOOD_FRINGE;
␈↓ ↓H␈↓ε␈↓¬FRGO4: 89:   (FRINGE CAR X*FRINGE CONS(CDR X,Y))
␈↓ ↓H␈↓¬                =FRINGE CONS(CAR X,CONS(CDR X,Y))  (82)␈↓ε
␈↓ ↓H␈↓εREWRITE   FRINGE CONS(X,Y) BY {FRINGE_CONSXY,FRGO1,FRGO2,FRGO3,FRGO4};
␈↓ ↓H␈↓ε␈↓¬FR_ROTN: 90:   FRINGE CONS(X,Y)=FRINGE CONS(CAR X,CONS(CDR X,Y))  (82)␈↓ε

␈↓ ↓H␈↓ε␈↓αInstantiate induction hypothesis␈↓ε
␈↓ ↓H␈↓εMONADIC         FRGO_HYP;
␈↓ ↓H␈↓ε␈↓¬91:   CAR FRINGE CONS(CAR X,CONS(CDR X,Y))=CAR GOPHER CONS(CAR X,CONS(CDR X,Y))
␈↓ ↓H␈↓¬    ∧CDR FRINGE CONS(CAR X,CONS(CDR X,Y))=FRINGE CDR GOPHER CONS(CAR X,CONS(CDR X,Y))
␈↓ ↓H␈↓¬    (82)␈↓ε

␈↓ ↓H␈↓ε␈↓αReplace␈↓ε  ␈↓¬CONS(CAR X,CONS(CDR X,Y))␈↓ε  ␈↓αby␈↓ε ␈↓¬CONS(X,Y)␈↓ε

␈↓ ↓H␈↓εTAUTEQ          GOPHER_CONS,FRGO_HYP;
␈↓ ↓H␈↓ε␈↓¬92:   GOPHER CONS(X,Y)=GOPHER CONS(CAR X,CONS(CDR X,Y))  (82)␈↓ε
␈↓ ↓H␈↓εSUBST   ↑ IN ↑↑;    SUBST   FR_ROTN IN ↑;
␈↓ ↓H␈↓ε␈↓¬94:   CAR FRINGE CONS(X,Y)=CAR GOPHER CONS(X,Y)
␈↓ ↓H␈↓¬        ∧CDR FRINGE CONS(X,Y)=FRINGE CDR GOPHER CONS(X,Y)  (82)␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ Y;    ⊃I   FRGO_HYP⊃↑;    ∀I   ↑ X;
␈↓ ↓H␈↓ε␈↓¬97:   ∀X.((¬ATOM X∧(∀Y.(CAR FRINGE CONS(CAR X,Y)=CAR GOPHER CONS(CAR X,Y)
␈↓ ↓H␈↓¬                        ∧CDR FRINGE CONS(CAR X,Y)=FRINGE CDR GOPHER CONS(CAR X,Y))
␈↓ ↓H␈↓¬                ∧∀Y.(CAR FRINGE CONS(CDR X,Y)=CAR GOPHER CONS(CDR X,Y)
␈↓ ↓H␈↓¬                        ∧CDR FRINGE CONS(CDR X,Y)=FRINGE CDR GOPHER CONS(CDR X,Y))))
␈↓ ↓H␈↓¬        ⊃∀Y.(CAR FRINGE CONS(X,Y)=CAR GOPHER CONS(X,Y)
␈↓ ↓H␈↓¬                ∧CDR FRINGE CONS(X,Y)=FRINGE CDR GOPHER CONS(X,Y)))  ␈↓ε

␈↓ ↓H␈↓αApply induction axiom

␈↓ ↓H␈↓εTAUT   FRGO_IND:#2   FRGO_IND,FRGO_ATM,↑;
␈↓ ↓H␈↓ε␈↓¬98:   ∀X Y.(CAR FRINGE CONS(X,Y)=CAR GOPHER CONS(X,Y)
␈↓ ↓H␈↓¬                ∧CDR FRINGE CONS(X,Y)=FRINGE CDR GOPHER CONS(X,Y))␈↓ε
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ ≥xix


␈↓ ↓H␈↓ε␈↓αNow use MAKEX to replace␈↓ε ␈↓¬CONS(X,Y)␈↓ε ␈↓αby␈↓ε ␈↓¬X␈↓ε

␈↓ ↓H␈↓ε∀E   ↑  CAR X,CDR X;   SUBSTR   MAKEX IN ↑;
␈↓ ↓H␈↓εMONADIC         ↑,XISNTATM,CARDEF1,CDRDEF1;
␈↓ ↓H␈↓ε␈↓¬101:   CAR FRINGE X=CAR GOPHER X∧CDR FRINGE X=FRINGE CDR GOPHER X  (3)␈↓ε
␈↓ ↓H␈↓ε⊃I  XISNTATM⊃↑;    ∀I   ↑ X;
␈↓ ↓H␈↓ε␈↓¬FRINGE_GOPHER: 103:    ∀X.(¬ATOM X⊃(CAR FRINGE X=CAR GOPHER X
␈↓ ↓H␈↓¬                                        ∧CDR FRINGE X=FRINGE CDR GOPHER X))  ␈↓ε

␈↓ ↓H␈↓α␈↓ ¬(Proving EQU_FRINGE

␈↓ ↓H␈↓εTAUT ;    SUBSTR   XISY IN ↑ OCC 2;   ⊃I  XISY⊃↑;
␈↓ ↓H␈↓ε␈↓¬106:    X=Y⊃FRINGE X=FRINGE Y  ␈↓ε
␈↓ ↓H␈↓εTAUTEQ    ↑;    ∀I  ↑ X Y;
␈↓ ↓H␈↓ε␈↓¬EQU_FRINGE: 108:    ∀X Y.((X=Y∨FRINGE X=FRINGE Y)≡FRINGE X=FRINGE Y)  ␈↓ε


␈↓ ↓H␈↓α␈↓ ¬!Proving SIZE_GOPHER


␈↓ ↓H␈↓ε␈↓αFirst show␈↓ε   ␈↓¬SIZE CDR GOPHER CONS(X,Y)<SIZE CONS(X,Y)␈↓ε

␈↓ ↓H␈↓ε∀E   SIZEDEF   CONS(X,Y);    MONADIC    ↑,CONSDF3;
␈↓ ↓H␈↓ε␈↓¬110:    SIZE CONS(X,Y)=(SIZE CAR CONS(X,Y)+SIZE CDR CONS(X,Y))  ␈↓ε
␈↓ ↓H␈↓εREWRITE   SIZE CONS(X,Y) BY {↑,CARCONS,CDRCONS};
␈↓ ↓H␈↓ε␈↓¬SIZECONSXY: 111:   SIZE CONS(X,Y)=(SIZE X+SIZE Y)  ␈↓ε
␈↓ ↓H␈↓ε∀I   ↑ X Y;
␈↓ ↓H␈↓ε␈↓¬SIZECONS: 112:   ∀X Y.SIZE CONS(X,Y)=(SIZE X+SIZE Y)  ␈↓ε

␈↓ ↓H␈↓ε␈↓αInduction axiom␈↓ε
␈↓ ↓H␈↓ε∧I   SEXPINDUCTION  [PHI←λX.∀Y.(SIZE CDR GOPHER CONS(X,Y)<SIZE CONS(X,Y))];
␈↓ ↓H␈↓ε␈↓¬LESS_IND: 113:   (∀X.(ATOM X⊃∀Y.SIZE CDR GOPHER CONS(X,Y)<SIZE CONS(X,Y))
␈↓ ↓H␈↓¬                ∧∀X.((¬ATOM X∧(∀Y.SIZE CDR GOPHER CONS(CAR X,Y)<SIZE CONS(CAR X,Y)
␈↓ ↓H␈↓¬                                ∧∀Y.SIZE CDR GOPHER CONS(CDR X,Y)<SIZE CONS(CDR X,Y)))
␈↓ ↓H␈↓¬                        ⊃∀Y.SIZE CDR GOPHER CONS(X,Y)<SIZE CONS(X,Y)))
␈↓ ↓H␈↓¬                ⊃∀X Y.SIZE CDR GOPHER CONS(X,Y)<SIZE CONS(X,Y)  ␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε ␈↓¬ATOM X␈↓ε

␈↓ ↓H␈↓εTAUTEQ   GOPHER CONS(X,Y)=CONS(X,Y)   GOPHER_CONS,XISATM;
␈↓ ↓H␈↓εREWRITE   SIZE CDR GOPHER CONS(X,Y) BY {↑,CDRCONS};
␈↓ ↓H␈↓ε␈↓¬115:   SIZE CDR GOPHER CONS(X,Y)=SIZE Y  (2)␈↓ε
␈↓ ↓H␈↓εMONADIC    SIZE X=1    SIZEDEF XISATM;    SUBSTR  ↑ IN SIZECONSXY;
␈↓ ↓H␈↓ε␈↓¬117:   SIZE CONS(X,Y)=(1+SIZE Y)  (2)␈↓ε
␈↓ ↓H␈↓εMONADIC         ↑↑↑:↑,ORDER,ISTOT_SIZE;
␈↓ ↓H␈↓ε␈↓¬118:   SIZE CDR GOPHER CONS(X,Y)<SIZE CONS(X,Y)  (2)␈↓ε
␈↓ ↓H␈↓ε∀I  ↑ Y;  ⊃I  XISATM⊃↑;    ∀I  ↑ X;
␈↓ ↓H␈↓ε␈↓¬LESS_ATM: 121:   ∀X.(ATOM X⊃∀Y.SIZE CDR GOPHER CONS(X,Y)<SIZE CONS(X,Y))  ␈↓ε

␈↓ ↓H␈↓ε␈↓αCase␈↓ε  ␈↓¬¬ATOM X␈↓ε

␈↓ ↓H␈↓ε␈↓αInduction hypothesis␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬LESS_HYP: 122:   ¬ATOM X∧(∀Y.SIZE CDR GOPHER CONS(CAR X,Y)<SIZE CONS(CAR X,Y)
␈↓ ↓H␈↓¬                        ∧∀Y.SIZE CDR GOPHER CONS(CDR X,Y)<SIZE CONS(CDR X,Y))  (122)␈↓ε
␈↓ ↓H␈↓xx␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓ε␈↓αShow␈↓ε  ␈↓¬SIZE CONS(CAR X,CONS(CDR X,Y))=SIZE CONS(X,Y)␈↓ε  ␈↓αusing a chain of equalities␈↓ε

␈↓ ↓H␈↓ε∀E   SIZECONS    CAR X,CONS(CDR X,Y);    MONADIC   ↑,CARDEF1,LESS_HYP;
␈↓ ↓H␈↓ε␈↓¬LESS1: 124:   SIZE CONS(CAR X,CONS(CDR X,Y))=(SIZE CAR X+SIZE CONS(CDR X,Y))  (122)␈↓ε
␈↓ ↓H␈↓ε∀E   SIZECONS   CDR X,Y;    MONADIC    ↑,CDRDEF1,LESS_HYP;
␈↓ ↓H␈↓ε␈↓¬LESS2: 126:   SIZE CONS(CDR X,Y)=(SIZE CDR X+SIZE Y)  (122)␈↓ε
␈↓ ↓H␈↓ε∀E   ASSOC   SIZE CAR X,SIZE CDR X,SIZE Y;
␈↓ ↓H␈↓εMONADIC         ↑,ISTOT_SIZE,CARDEF1,CDRDEF1,LESS_HYP;
␈↓ ↓H␈↓ε␈↓¬LESS3: 128:   (SIZE CAR X+(SIZE CDR X+SIZE Y))=((SIZE CAR X+SIZE CDR X)+SIZE Y)  (122)␈↓ε
␈↓ ↓H␈↓εMONADIC         SIZEDEF,LESS_HYP;
␈↓ ↓H␈↓ε␈↓¬LESS4: 129:   (SIZE CAR X+SIZE CDR X)=SIZE X  (122)␈↓ε
␈↓ ↓H␈↓εTAUTEQ    SIZECONSXY;
␈↓ ↓H␈↓ε␈↓¬LESS5: 130:   (SIZE X+SIZE Y)=SIZE CONS(X,Y)  ␈↓ε
␈↓ ↓H␈↓εREWRITE   SIZE CONS(CAR X,CONS(CDR X,Y))  BY  {LESS1,LESS2,LESS3,LESS4,LESS5};
␈↓ ↓H␈↓ε␈↓¬131:   SIZE CONS(CAR X,CONS(CDR X,Y))=SIZE CONS(X,Y)  (122)␈↓ε

␈↓ ↓H␈↓ε␈↓αShow␈↓ε  ␈↓¬SIZE CDR GOPHER CONS(X,Y)=SIZE CDR GOPHER CONS(CAR X,CONS(CDR X,Y))␈↓ε

␈↓ ↓H␈↓εTAUTEQ   GOPHER CONS(X,Y)=GOPHER CONS(CAR X,CONS(CDR X,Y))
␈↓ ↓H␈↓ε                GOPHER_CONS,LESS_HYP;
␈↓ ↓H␈↓εREWRITE SIZE CDR GOPHER CONS(X,Y) BY {↑};
␈↓ ↓H␈↓ε␈↓¬133:   SIZE CDR GOPHER CONS(X,Y)=SIZE CDR GOPHER CONS(CAR X,CONS(CDR X,Y))  (122)␈↓ε

␈↓ ↓H␈↓αCombine these two equalities with the induction hypothesis

␈↓ ↓H␈↓εMONADIC SIZE CDR GOPHER CONS(X,Y)<SIZE CONS(X,Y) ↑↑↑,↑,LESS_HYP;
␈↓ ↓H␈↓ε∀I ↑ Y; ⊃I LESS_HYP⊃↑; ∀I ↑ X;
␈↓ ↓H␈↓ε␈↓¬137:   ∀X.((¬ATOM X∧(∀Y.SIZE CDR GOPHER CONS(CAR X,Y)<SIZE CONS(CAR X,Y)
␈↓ ↓H␈↓¬                        ∧∀Y.SIZE CDR GOPHER CONS(CDR X,Y)<SIZE CONS(CDR X,Y)))
␈↓ ↓H␈↓¬                ⊃∀Y.SIZE CDR GOPHER CONS(X,Y)<SIZE CONS(X,Y))  ␈↓ε

␈↓ ↓H␈↓αApply induction axiom

␈↓ ↓H␈↓εTAUT   LESS_IND,LESS_ATM,↑;
␈↓ ↓H␈↓ε␈↓¬138:   ∀X Y.SIZE CDR GOPHER CONS(X,Y)<SIZE CONS(X,Y)  ␈↓ε

␈↓ ↓H␈↓ε␈↓αNow show␈↓ε  ␈↓¬¬ATOM X⊃SIZE CDR GOPHER X<SIZE X␈↓ε

␈↓ ↓H␈↓ε∀E   ↑ CAR X,CDR X;    SUBSTR   MAKEX IN ↑;
␈↓ ↓H␈↓εMONADIC    ↑,CARDEF1,CDRDEF1,XISNTATM; ⊃I XISNTATM⊃↑;    ∀I   ↑ X;
␈↓ ↓H␈↓ε␈↓¬LESS_CDR_GOPHER: 143:   ∀X.(¬ATOM X⊃SIZE CDR GOPHER X<SIZE X)  ␈↓ε

␈↓ ↓H␈↓αApply the axiom relation < and + to the above relation to obtain SIZE_GOPHER

␈↓ ↓H␈↓ε∀E   ORDER_PLUS   SIZE CDR GOPHER X,SIZE X,SIZE CDR GOPHER Y,SIZE Y;
␈↓ ↓H␈↓εMONADIC    ↑,LESS_CDR_GOPHER,ISTOT_SIZE,GOOD_GOPHER;    ∀I   ↑ X Y;
␈↓ ↓H␈↓ε␈↓¬SIZE_GOPHER: 146:   ∀X Y.((¬ATOM X∧¬ATOM Y)
␈↓ ↓H␈↓¬                        ⊃(SIZE CDR GOPHER X+SIZE CDR GOPHER Y)<(SIZE X+SIZE Y))␈↓ε
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ ≥xxi


␈↓ ↓H␈↓α␈↓ ∧SProving the SAMEFRINGE theorem


␈↓ ↓H␈↓αA brief summary of the proof

␈↓ ↓H␈↓        ␈↓↓The theorem, ␈↓¬THM, ␈↓↓is the conjunct of three theorems:

␈↓ ↓H␈↓↓                        ␈↓¬THM1: ISTV SAMEFRINGEA(X,Y),␈↓↓
␈↓ ↓H␈↓↓                        ␈↓¬THM2: SAMEFRINGE(X,Y)=(X=Y)∨((¬ATOM X∧¬ATOM Y)∧SAME(GOPHER X,GOPHER Y)),␈↓↓
␈↓ ↓H␈↓↓                        ␈↓¬THM3: SAMEFRINGE(X,Y)≡FRINGE X=FRINGE Y.␈↓↓

␈↓ ↓H␈↓↓The proof is by induction on ␈↓¬SIZE X+SIZE Y.␈↓↓  The induction predicate is

␈↓ ↓H␈↓↓                        ␈↓¬PSI(N)≡∀X Y.(SIZE X+SIZE Y=N⊃THM(X,Y)).␈↓↓

␈↓ ↓H␈↓↓To␈α⊗prove␈α⊗that␈α⊗the␈α⊗theorem␈α⊗follows␈α⊗from␈α⊗the␈α⊗induction␈α⊗hypothesis␈α⊗two␈α⊗cases␈α⊗are␈α⊗considered:
␈↓ ↓H␈↓↓␈↓¬ATOMXY≡(ATOM X ∨ ATOM Y)␈↓↓␈α∂and␈α∂␈↓¬NOTATMXY≡(¬ATOM X ∧¬ATOM Y).␈↓↓␈α∂  In␈α∂the␈α∂first␈α∂case␈α∂the␈α∞theorem
␈↓ ↓H␈↓↓follows␈α
by␈αdirect␈α
computation.␈α
  In␈αthe␈α
second␈α
case␈α ␈↓¬THMCDRGO≡THM(CDR GOPHER X, CDR GOPHER Y)␈↓↓
␈↓ ↓H␈↓↓is derived from the induction hypothesis and used to prove the theorem for ␈↓¬(X,Y).␈↓↓

␈↓ ↓H␈↓αLemmas  needed for proof of SAMEFRINGE theorem

␈↓ ↓H␈↓¬AXIOM TV_LEMMAS:
␈↓ ↓H␈↓¬        TVEEQ: ∀X Y.(ISTV X EEQ Y)  ;
␈↓ ↓H␈↓¬        EQEEQ: ∀X Y.((X EEQ Y=TT)≡(X=Y));
␈↓ ↓H␈↓¬        TVOOR: ∀P Q.(ISTV(P OOR Q));
␈↓ ↓H␈↓¬        TVAAND: ∀P Q.(ISTV(P AAND Q));
␈↓ ↓H␈↓¬        EQOOR: ∀P Q.((P OOR Q = TT)≡(P=TT ∨ Q=TT));
␈↓ ↓H␈↓¬        EQAAND: ∀P Q.((P AAND Q = TT)≡(P=TT ∧ Q=TT));
␈↓ ↓H␈↓¬        TVNOTATM: ∀X Y.((ISTV (NNOT AATOM X AAND NNOT AATOM Y)));
␈↓ ↓H␈↓¬        EQNOTATM: ∀X Y.((((NNOT AATOM X AAND NNOT AATOM Y)= TT)≡(¬ATOM X∧¬ATOM Y)));
␈↓ ↓H␈↓¬        POORF: ∀P.(P OOR FF=P);
␈↓ ↓H␈↓¬        FAANDQQ: ∀QQ.(FF AAND QQ = FF);
␈↓ ↓H␈↓¬;;

␈↓ ↓H␈↓¬AXIOM GOPHER_FRINGE_SIZE_LEMMAS:
␈↓ ↓H␈↓¬        GOOD_GOPHER: ∀X.((¬ATOM X)⊃(ISSEXP GOPHER X∧ISSEXP CAR GOPHER X
␈↓ ↓H␈↓¬                                        ∧ISSEXP CDR GOPHER X));
␈↓ ↓H␈↓¬        GOOD_FRINGE: ∀X.(¬ATOM FRINGE X∧ISSEXP FRINGE X);
␈↓ ↓H␈↓¬        ISTOT_SIZE:     ∀X.NATNUM(SIZE X);
␈↓ ↓H␈↓¬        FRINGE_ATM: ∀X Y.((ATOM X∨ATOM Y)⊃((FRINGE X=FRINGE Y)≡(X=Y)));
␈↓ ↓H␈↓¬        FRINGE_GOPHER:
␈↓ ↓H␈↓¬            ∀X.((¬ATOM X)⊃(CAR FRINGE X=CAR GOPHER X∧CDR FRINGE X=FRINGE CDR GOPHER X));
␈↓ ↓H␈↓¬        EQU_FRINGE: ∀X Y.(X=Y∨FRINGE X=FRINGE Y≡FRINGE X=FRINGE Y);
␈↓ ↓H␈↓¬        SIZE_GOPHER:
␈↓ ↓H␈↓¬           ∀X Y.((¬ATOM X∧¬ATOM Y)
␈↓ ↓H␈↓¬                        ⊃((SIZE CDR GOPHER X+SIZE CDR GOPHER Y)<(SIZE X+SIZE Y)));
␈↓ ↓H␈↓¬;;
␈↓ ↓H␈↓xxii␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓αStandard hypotheses

␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬XISATM: 1:   ATOM X  (1)␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬YISATM: 2:   ATOM Y  (2)␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬ATOMXY: 3:   ATOM X∨ATOM Y  (3)␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬NOTATMXY: 4:   ¬ATOM X∧¬ATOM Y  (4)␈↓ε
␈↓ ↓H␈↓εTAUT ;
␈↓ ↓H␈↓ε␈↓¬ATOMXYTAUT: 5:   (ATOM X∨ATOM Y)∨(¬ATOM X∧¬ATOM Y)  ␈↓ε

␈↓ ↓H␈↓αDefinitions

␈↓ ↓H␈↓ε∀E   SAMEFRINGEADEF   X,Y;
␈↓ ↓H␈↓ε␈↓¬SFAXY: 6:   SAMEFRINGEA(X,Y)=((X EEQ Y) OOR ((NNOT AATOM X AAND NNOT AATOM Y)
␈↓ ↓H␈↓¬                                                        AAND SAMEA(GOPHER X,GOPHER Y)))  ␈↓ε
␈↓ ↓H␈↓ε∀E   SAMEFRINGEDEF   X,Y;
␈↓ ↓H␈↓ε␈↓¬SFXY: 7:   SAMEFRINGE(X,Y)≡SAMEFRINGEA(X,Y)=TT  ␈↓ε
␈↓ ↓H␈↓ε∀E   THMDEF   X Y;
␈↓ ↓H␈↓ε␈↓¬THMXY: 8:   THM(X,Y)≡(ISTV SAMEFRINGEA(X,Y)
␈↓ ↓H␈↓¬                ∧((SAMEFRINGE(X,Y)≡(X=Y∨((¬ATOM X∧¬ATOM Y)∧SAME(GOPHER X,GOPHER Y))))
␈↓ ↓H␈↓¬                ∧(SAMEFRINGE(X,Y)≡FRINGE X=FRINGE Y)))  ␈↓ε

␈↓ ↓H␈↓αUseful facts in useful form

␈↓ ↓H␈↓ε∀E   TVNOTATM   X Y;
␈↓ ↓H␈↓ε␈↓¬TVNOTATMXY: 9:   ISTV (NNOT AATOM X AAND NNOT AATOM Y)  ␈↓ε
␈↓ ↓H␈↓ε∀E   EQNOTATM   X Y;
␈↓ ↓H␈↓ε␈↓¬EQNOTATMXY: 10:   (NNOT AATOM X AAND NNOT AATOM Y)=TT≡(¬ATOM X∧¬ATOM Y)  ␈↓ε
␈↓ ↓H␈↓ε∀E   TVEEQ   X,Y;
␈↓ ↓H␈↓ε␈↓¬TVEEQXY: 11:   ISTV (X EEQ Y)  ␈↓ε
␈↓ ↓H␈↓ε∀E   EQEEQ   X,Y;
␈↓ ↓H␈↓ε␈↓¬EQEEQXY: 12:   (X EEQ Y)=TT≡X=Y  ␈↓ε
␈↓ ↓H␈↓ε∀E   GOOD_GOPHER   X;
␈↓ ↓H␈↓ε␈↓¬GOODGOX: 13:   ¬ATOM X⊃(ISSEXP GOPHER X∧(ISSEXP CAR GOPHER X∧ISSEXP CDR GOPHER X))␈↓ε
␈↓ ↓H␈↓ε∀E   GOOD_GOPHER   Y;
␈↓ ↓H␈↓ε␈↓¬GOODGOY: 14:   ¬ATOM Y⊃(ISSEXP GOPHER Y∧(ISSEXP CAR GOPHER Y∧ISSEXP CDR GOPHER Y))␈↓ε


␈↓ ↓H␈↓α␈↓ ¬←Case ATOMXY


␈↓ ↓H␈↓ε␈↓αCompute␈↓ε  ␈↓¬SAMEFRINGEA(X,Y)␈↓ε

␈↓ ↓H␈↓ε∀E   FAANDQQ   SAMEA(GOPHER X, GOPHER Y);    ∀E   ETVSAMEA   GOPHER X,GOPHER Y;
␈↓ ↓H␈↓ε⊃E   ↑,↑↑;
␈↓ ↓H␈↓ε␈↓¬17:   (FF AAND SAMEA(GOPHER X,GOPHER Y))=FF  ␈↓ε
␈↓ ↓H␈↓ε∀E   TVEXT   NNOT AATOM X AAND NNOT AATOM Y;
␈↓ ↓H␈↓εTAUT            TVSET,TVNOTATMXY,EQNOTATMXY,ATOMXY,↑;
␈↓ ↓H␈↓ε␈↓¬19:   (NNOT AATOM X AAND NNOT AATOM Y)=FF  (3)␈↓ε
␈↓ ↓H␈↓ε∀E   POORF   X EEQ Y;
␈↓ ↓H␈↓εTAUT            ↑,TVEEQXY;
␈↓ ↓H␈↓ε␈↓¬21:   ((X EEQ Y) OOR FF)=(X EEQ Y)  ␈↓ε
␈↓ ↓H␈↓εREWRITE   SAMEFRINGEA(X,Y) BY {SFAXY,↑↑↑,↑↑↑↑↑,↑};
␈↓ ↓H␈↓ε␈↓¬22:   SAMEFRINGEA(X,Y)=(X EEQ Y)  (3)␈↓ε
␈↓ ↓H␈↓␈↓ ¬dAPPENDIX II␈↓ xxiii


␈↓ ↓H␈↓αUse properties of EEQ and FRINGE of an atom to conclude THM

␈↓ ↓H␈↓ε∀E   FRINGE_ATM   X Y;
␈↓ ↓H␈↓εTAUTEQ          THMXY,SFXY,ATOMXY,TVEEQXY,EQEEQXY,↑↑:↑;
␈↓ ↓H␈↓ε␈↓¬THMATM: 24:   THM(X,Y)  (3)␈↓ε


␈↓ ↓H␈↓α␈↓ ¬HCase NOTATMXY

␈↓ ↓H␈↓ε␈↓αInduction axiom␈↓ε
␈↓ ↓H␈↓ε∧I   NUMBINDUCTION   [PSI←λN.∀X Y.((SIZE X+SIZE Y=N)⊃THM(X,Y))];
␈↓ ↓H␈↓ε␈↓¬SFIND: 25:   ∀N.(∀M.(M<N⊃∀X Y.((SIZE X+SIZE Y)=M⊃THM(X,Y)))
␈↓ ↓H␈↓¬                ⊃∀X Y.((SIZE X+SIZE Y)=N⊃THM(X,Y)))⊃∀N X Y.((SIZE X+SIZE Y)=N⊃THM(X,Y))  ␈↓ε

␈↓ ↓H␈↓ε␈↓αInduction hypotheses␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬NHYP: 26:   (SIZE X+SIZE Y)=N  (26)␈↓ε
␈↓ ↓H␈↓εASSUME ;
␈↓ ↓H␈↓ε␈↓¬SFINDHYP: 27:   ∀M.(M<N⊃∀X Y.((SIZE X+SIZE Y)=M⊃THM(X,Y)))  (27)␈↓ε

␈↓ ↓H␈↓αShow THMCDRGO

␈↓ ↓H␈↓ε∀E   SFINDHYP   SIZE CDR GOPHER X+SIZE CDR GOPHER Y;
␈↓ ↓H␈↓εMONADIC         ISTOT_PLUS,ISTOT_SIZE,GOOD_GOPHER,NOTATMXY;
␈↓ ↓H␈↓ε␈↓¬29:   NATNUM(SIZE CDR GOPHER X+SIZE CDR GOPHER Y)  (4)␈↓ε
␈↓ ↓H␈↓ε∀E   SIZE_GOPHER   X Y;    TAUTEQ    ↑↑↑:↑,NOTATMXY,NHYP;
␈↓ ↓H␈↓ε␈↓¬31:   ∀X1 Y1.((SIZE X1+SIZE Y1)=(SIZE CDR GOPHER X+SIZE CDR GOPHER Y)⊃THM(X1,Y1))
␈↓ ↓H␈↓¬          (4 26 27)␈↓ε
␈↓ ↓H␈↓ε∀E   ↑   CDR GOPHER X,CDR GOPHER Y;    TAUTEQ    ↑, NOTATMXY, GOODGOX,GOODGOY;
␈↓ ↓H␈↓ε␈↓¬THMCDRGO: 33:   THM(CDR GOPHER X,CDR GOPHER Y)  (4 26 27)␈↓ε


␈↓ ↓H␈↓αInstantiate the lemmas and definitions to be used.

␈↓ ↓H␈↓ε␈↓¬CASENOTATM:  ␈↓ε

␈↓ ↓H␈↓αProving THM1

␈↓ ↓H␈↓ε∀E   TVEEQ    CAR GOPHER X,CAR GOPHER Y;
␈↓ ↓H␈↓ε∀E   TVAAND   CAR GOPHER X EEQ CAR GOPHER Y,SAMEFRINGEA(CDR GOPHER X,CDR GOPHER Y);
␈↓ ↓H␈↓ε∀E   TVAAND   NNOT AATOM X AAND NNOT AATOM Y,SAMEA(GOPHER X,GOPHER Y);
␈↓ ↓H␈↓ε∀E   TVOOR    X EEQ Y,(NNOT AATOM X AAND NNOT AATOM Y) AAND SAMEA(GOPHER X,GOPHER Y);

␈↓ ↓H␈↓αProving THM2

␈↓ ↓H␈↓ε∀E   EQOOR    X EEQ Y,(NNOT AATOM X AAND NNOT AATOM Y) AAND SAMEA(GOPHER X,GOPHER Y);
␈↓ ↓H␈↓ε∀E   EQAAND   NNOT AATOM X AAND NNOT AATOM Y,SAMEA(GOPHER X,GOPHER Y);
␈↓ ↓H␈↓ε∀E   SAMEDEF  GOPHER X,GOPHER Y;
␈↓ ↓H␈↓xxiv␈↓ ¬dAPPENDIX II␈↓ H


␈↓ ↓H␈↓αProving THM3

␈↓ ↓H␈↓ε␈↓αShow␈↓ε ␈↓¬SAMEA(GOPHER X,GOPHER Y)=TT≡
␈↓ ↓H␈↓¬           (CAR GOPHER X=CAR GOPHER Y)∧(FRINGE CDR GOPHER X=FRINGE CDR GOPHER Y)␈↓ε
␈↓ ↓H␈↓ε∀E   SAMEADEF   GOPHER X,GOPHER Y;
␈↓ ↓H␈↓ε∀E   SAMEFRINGEDEF   CDR GOPHER X, CDR GOPHER Y;
␈↓ ↓H␈↓ε∀E   THMDEF   CDR GOPHER X,CDR GOPHER Y;
␈↓ ↓H␈↓ε∀E   EQAAND   CAR GOPHER X EEQ CAR GOPHER Y,SAMEFRINGEA(CDR GOPHER X,CDR GOPHER Y);
␈↓ ↓H␈↓ε∀E   EQEEQ    CAR GOPHER X,CAR GOPHER Y;

␈↓ ↓H␈↓ε␈↓αThen use FRINGE_GOPHER to get␈↓ε
␈↓ ↓H␈↓ε        ␈↓¬SAMEFRINGE(X,Y)≡X=Y∨(CAR FRINGE X=CAR FRINGE Y∧CDR FRINGE X=CDR FRINGE Y)␈↓ε

␈↓ ↓H␈↓ε∀E   FRINGE_GOPHER   X;
␈↓ ↓H␈↓ε∀E   FRINGE_GOPHER   Y;

␈↓ ↓H␈↓ε␈↓αNow use EQSEXP to replace the second disjunct by␈↓ε ␈↓¬FRINGE X=FRINGE Y␈↓ε
␈↓ ↓H␈↓ε                ␈↓αand EQU_FRINGE to absorb the␈↓ε ␈↓¬X=Y␈↓ε

␈↓ ↓H␈↓ε∀E   GOOD_FRINGE   X;
␈↓ ↓H␈↓ε∀E   GOOD_FRINGE   Y;
␈↓ ↓H␈↓ε∀E   EQSEXP   FRINGE X,FRINGE Y;
␈↓ ↓H␈↓ε∀E   EQU_FRINGE   X Y;

␈↓ ↓H␈↓ε␈↓αConclude THM in case NOTATMXY␈↓ε
␈↓ ↓H␈↓εTAUTEQ          CASENOTATM:↑,GOODGOX,GOODGOY,NOTATMXY,THMCDRGO,
␈↓ ↓H␈↓ε                SFAXY,TVNOTATMXY,TVEEQXY,
␈↓ ↓H␈↓ε                SFXY,EQNOTATMXY,EQEEQXY,THMXY;
␈↓ ↓H␈↓ε␈↓¬52:   THM(X,Y)  (4 26 27)␈↓ε

␈↓ ↓H␈↓αCombine the cases ATMXY and NOTATMXY

␈↓ ↓H␈↓ε∨E   ATOMXYTAUT   THMATM,↑;
␈↓ ↓H␈↓ε␈↓¬53:   THM(X,Y)  (26 27)␈↓ε

␈↓ ↓H␈↓αComplete the induction

␈↓ ↓H␈↓ε⊃I   NHYP⊃↑;    ∀I   ↑ X Y;
␈↓ ↓H␈↓ε⊃I   SFINDHYP⊃↑;    ∀I   ↑ N;
␈↓ ↓H␈↓ε␈↓¬57:   ∀N.(∀M.(M<N⊃∀X Y.((SIZE X+SIZE Y)=M⊃THM(X,Y)))⊃∀X Y.((SIZE X+SIZE Y)=N⊃THM(X,Y)))␈↓ε
␈↓ ↓H␈↓ε⊃E   ↑,SFIND;
␈↓ ↓H␈↓ε␈↓¬58:   ∀N X Y.((SIZE X+SIZE Y)=N⊃THM(X,Y))  ␈↓ε

␈↓ ↓H␈↓αExtract THM from induction predicate

␈↓ ↓H␈↓εMONADIC         ISTOT_PLUS,ISTOT_SIZE;
␈↓ ↓H␈↓ε␈↓¬59:   NATNUM(SIZE X+SIZE Y)  ␈↓ε
␈↓ ↓H␈↓ε∀E   ↑↑ SIZE X + SIZE Y;    ⊃E   ↑,↑↑;
␈↓ ↓H␈↓ε␈↓¬61:   ∀X1 Y1.((SIZE X1+SIZE Y1)=(SIZE X+SIZE Y)⊃THM(X1,Y1))  ␈↓ε
␈↓ ↓H␈↓ε∀E   ↑ X Y ;    TAUT   ↑;    ∀I   ↑ X Y;
␈↓ ↓H␈↓ε␈↓¬SFTHM: 64:   ∀X Y.THM(X,Y)  ␈↓ε
␈↓ ↓H␈↓␈↓ ¬←APPENDIX III␈↓ ?i


␈↓ ↓H␈↓α␈↓ ¬¬MACLISP listing of LCOM0

␈↓ ↓H␈↓ε(DECLARE (SETQ NO-DISK-HACKS T))
␈↓ ↓H␈↓ε(DECLARE (READ))

␈↓ ↓H␈↓ε(DEFPROP LC0FNS
␈↓ ↓H␈↓ε (LC0FNS COMPL COMP PRUP MKPUSH COMPEXP COMPLIS LOADAC COMCOND COMBOOL COMPANDOR)
␈↓ ↓H␈↓εVALUE)

␈↓ ↓H␈↓ε(DEFPROP COMPL
␈↓ ↓H␈↓ε (LAMBDA(FILE)
␈↓ ↓H␈↓ε  (UWRITE)
␈↓ ↓H␈↓ε  (APPLY (QUOTE EREAD) FILE)
␈↓ ↓H␈↓ε  (SELECT-DISK-INPUT
␈↓ ↓H␈↓ε   (READ-UNTIL-EOF
␈↓ ↓H␈↓ε    WITH
␈↓ ↓H␈↓ε    Z
␈↓ ↓H␈↓ε    DO
␈↓ ↓H␈↓ε    (COND ((OR (EQ (CAR Z) (QUOTE DEFUN)) (AND (EQ (CAR Z) (QUOTE DEFPROP)) (EQ (CADDDR Z) (QUOTE EXPR))))
␈↓ ↓H␈↓ε           (PROG (PROG)
␈↓ ↓H␈↓ε                 (SETQ PROG
␈↓ ↓H␈↓ε                       (COND ((EQ (CAR Z) (QUOTE DEFUN)) (COMP (CADR Z) (CADDR Z) (CADDDR Z)))
␈↓ ↓H␈↓ε                             (T (COMP (CADR Z) (CADR (CADDR Z)) (CADDR (CADDR Z))))))
␈↓ ↓H␈↓ε                 (UNSELECT-TTY (SELECT-DISK-OUTPUT (MAPC (FUNCTION PRINT) PROG)))
␈↓ ↓H␈↓ε                 (PRINT (LIST (CADR Z) (LENGTH PROG)))))
␈↓ ↓H␈↓ε          (T (UNSELECT-TTY (SELECT-DISK-OUTPUT (PRINT Z))))))
␈↓ ↓H␈↓ε   (APPLY (QUOTE UFILE) (LIST (CAR FILE) (QUOTE LAP)))
␈↓ ↓H␈↓ε   (QUOTE ENDCOMP)))
␈↓ ↓H␈↓εFEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMP
␈↓ ↓H␈↓ε (LAMBDA(FN VARS EXP)
␈↓ ↓H␈↓ε  ((LAMBDA(N)
␈↓ ↓H␈↓ε    (APPEND (LIST (LIST (QUOTE LAP) FN (QUOTE SUBR)))
␈↓ ↓H␈↓ε            (MKPUSH N 1)
␈↓ ↓H␈↓ε            (COMPEXP EXP (MINUS N) (PRUP VARS 1))
␈↓ ↓H␈↓ε            (LIST (LIST (QUOTE SUB) (QUOTE P) (LIST (QUOTE %) 0 0 N N)))
␈↓ ↓H␈↓ε            (QUOTE ((POPJ P) NIL))))
␈↓ ↓H␈↓ε   (LENGTH VARS)))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP PRUP
␈↓ ↓H␈↓ε (LAMBDA (VARS N) (COND ((NULL VARS) NIL) (T (CONS (CONS (CAR VARS) N) (PRUP (CDR VARS) (ADD1 N))))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP MKPUSH
␈↓ ↓H␈↓ε (LAMBDA (N M) (COND ((LESSP N M) NIL) (T (CONS (LIST (QUOTE PUSH) (QUOTE P) M) (MKPUSH N (ADD1 M))))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMPEXP
␈↓ ↓H␈↓ε (LAMBDA(EXP M VPR)
␈↓ ↓H␈↓ε  (COND ((NULL EXP) (QUOTE ((MOVEI 1 0))))
␈↓ ↓H␈↓ε        ((EQ EXP T) (QUOTE ((MOVEI 1 (QUOTE T)))))
␈↓ ↓H␈↓ε        ((NUMBERP EXP) (LIST (LIST (QUOTE MOVEI) 1 (LIST (QUOTE QUOTE) EXP))))
␈↓ ↓H␈↓ε        ((ATOM EXP) (LIST (LIST (QUOTE MOVE) 1 (PLUS M (CDR (ASSOC EXP VPR))) (QUOTE P))))
␈↓ ↓H␈↓ε        ((OR (EQ (CAR EXP) (QUOTE AND)) (EQ (CAR EXP) (QUOTE OR)) (EQ (CAR EXP) (QUOTE NOT)))
␈↓ ↓H␈↓ε         ((LAMBDA(L1 L2)
␈↓ ↓H␈↓ε           (APPEND (COMBOOL EXP M L1 NIL VPR)
␈↓ ↓H␈↓ε                   (LIST (QUOTE (MOVEI 1 (QUOTE T))) (LIST (QUOTE JRST) 0 L2) L1 (QUOTE (MOVEI 1 0)) L2)))
␈↓ ↓H␈↓ε          (GENSYM)
␈↓ ↓H␈↓ε          (GENSYM)))
␈↓ ↓H␈↓ε        ((EQ (CAR EXP) (QUOTE COND)) (COMCOND (CDR EXP) M (GENSYM) VPR))
␈↓ ↓H␈↓ε        ((EQ (CAR EXP) (QUOTE QUOTE)) (LIST (LIST (QUOTE MOVEI) 1 EXP)))
␈↓ ↓H␈↓ε        ((ATOM (CAR EXP))
␈↓ ↓H␈↓ε         ((LAMBDA(N)
␈↓ ↓H␈↓ii␈↓ ¬←APPENDIX III␈↓ H


␈↓ ↓H␈↓ε           (APPEND (COMPLIS (CDR EXP) M VPR)
␈↓ ↓H␈↓ε                   (LOADAC (DIFFERENCE 1 N) 1)
␈↓ ↓H␈↓ε                   (LIST (LIST (QUOTE SUB) (QUOTE P) (LIST (QUOTE %) 0 0 N N)))
␈↓ ↓H␈↓ε                   (LIST (LIST (QUOTE CALL) N (LIST (QUOTE QUOTE) (CAR EXP))))))
␈↓ ↓H␈↓ε          (LENGTH (CDR EXP))))
␈↓ ↓H␈↓ε        ((EQ (CAAR EXP) (QUOTE LAMBDA))
␈↓ ↓H␈↓ε         ((LAMBDA(N)
␈↓ ↓H␈↓ε           (APPEND (COMPLIS (CDR EXP) M VPR)
␈↓ ↓H␈↓ε                   (COMPEXP (CADDAR EXP) (DIFFERENCE M N) (APPEND (PRUP (CADAR EXP) (DIFFERENCE 1 M)) VPR))
␈↓ ↓H␈↓ε                   (LIST (LIST (QUOTE SUB) (QUOTE P) (LIST (QUOTE %) 0 0 N N)))))
␈↓ ↓H␈↓ε          (LENGTH (CDR EXP))))
␈↓ ↓H␈↓ε        (T NIL)))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMPLIS
␈↓ ↓H␈↓ε (LAMBDA(U M VPR)
␈↓ ↓H␈↓ε  (COND ((NULL U) NIL)
␈↓ ↓H␈↓ε        (T (APPEND (COMPEXP (CAR U) M VPR) (QUOTE ((PUSH P 1))) (COMPLIS (CDR U) (SUB1 M) VPR)))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP LOADAC
␈↓ ↓H␈↓ε (LAMBDA(N K)
␈↓ ↓H␈↓ε  (COND ((GREATERP N 0) NIL) (T (CONS (LIST (QUOTE MOVE) K N (QUOTE P)) (LOADAC (ADD1 N) (ADD1 K))))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMCOND
␈↓ ↓H␈↓ε (LAMBDA(U M L VPR)
␈↓ ↓H␈↓ε  (COND ((NULL U) (LIST L))
␈↓ ↓H␈↓ε        (T
␈↓ ↓H␈↓ε         ((LAMBDA(L1)
␈↓ ↓H␈↓ε           (APPEND (COMBOOL (CAAR U) M L1 NIL VPR)
␈↓ ↓H␈↓ε                   (COMPEXP (CADAR U) M VPR)
␈↓ ↓H␈↓ε                   (LIST (LIST (QUOTE JRST) 0 L) L1)
␈↓ ↓H␈↓ε                   (COMCOND (CDR U) M L VPR)))
␈↓ ↓H␈↓ε          (GENSYM)))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMBOOL
␈↓ ↓H␈↓ε (LAMBDA(P M L FLG VPR)
␈↓ ↓H␈↓ε  (COND ((ATOM P) (APPEND (COMPEXP P M VPR) (LIST (LIST (COND (FLG (QUOTE JUMPN)) (T (QUOTE JUMPE))) 1 L))))
␈↓ ↓H␈↓ε        ((EQ (CAR P) (QUOTE AND))
␈↓ ↓H␈↓ε         (COND ((NOT FLG) (COMPANDOR (CDR P) M L NIL VPR))
␈↓ ↓H␈↓ε               (T
␈↓ ↓H␈↓ε                ((LAMBDA(L1)
␈↓ ↓H␈↓ε                  (APPEND (COMPANDOR (CDR P) M L1 NIL VPR) (LIST (LIST (QUOTE JRST) 0 L)) (LIST L1)))
␈↓ ↓H␈↓ε                 (GENSYM)))))
␈↓ ↓H␈↓ε        ((EQ (CAR P) (QUOTE OR))
␈↓ ↓H␈↓ε         (COND (FLG (COMPANDOR (CDR P) M L T VPR))
␈↓ ↓H␈↓ε               (T
␈↓ ↓H␈↓ε                ((LAMBDA (L1) (APPEND (COMPANDOR (CDR P) M L1 T VPR) (LIST (LIST (QUOTE JRST) 0 L)) (LIST L1)))
␈↓ ↓H␈↓ε                 (GENSYM)))))
␈↓ ↓H␈↓ε        ((EQ (CAR P) (QUOTE NOT)) (COMBOOL (CADR P) M L (NOT FLG) VPR))
␈↓ ↓H␈↓ε        (T (APPEND (COMPEXP P M VPR) (LIST (LIST (COND (FLG (QUOTE JUMPN)) (T (QUOTE JUMPE))) 1 L))))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMPANDOR
␈↓ ↓H␈↓ε (LAMBDA(U M L FLG VPR)
␈↓ ↓H␈↓ε  (COND ((NULL U) NIL) (T (APPEND (COMBOOL (CAR U) M L FLG VPR) (COMPANDOR (CDR U) M L FLG VPR)))))
␈↓ ↓H␈↓εEXPR)
␈↓ ↓H␈↓␈↓ ¬]APPENDIX IV␈↓ ?i


␈↓ ↓H␈↓α␈↓ ¬∧MACLISP listing of LCOM4

␈↓ ↓H␈↓ε(DECLARE (SETQ NO-DISK-HACKS T))
␈↓ ↓H␈↓ε(DECLARE (READ))

␈↓ ↓H␈↓ε(DEFPROP COMPFCNS
␈↓ ↓H␈↓ε (COMPFCNS COMPL
␈↓ ↓H␈↓ε           COMP
␈↓ ↓H␈↓ε           SUBSTACK
␈↓ ↓H␈↓ε           PRUP
␈↓ ↓H␈↓ε           MKPUSH
␈↓ ↓H␈↓ε           COMPEXP
␈↓ ↓H␈↓ε           STACKUP
␈↓ ↓H␈↓ε           CCCHAIN
␈↓ ↓H␈↓ε           COMPC
␈↓ ↓H␈↓ε           COMCOND
␈↓ ↓H␈↓ε           COMPLISA
␈↓ ↓H␈↓ε           CCOUNT
␈↓ ↓H␈↓ε           LOADAC
␈↓ ↓H␈↓ε           COMPLIS
␈↓ ↓H␈↓ε           CLASSIFY
␈↓ ↓H␈↓ε           CLASS1
␈↓ ↓H␈↓ε           CLASS2
␈↓ ↓H␈↓ε           MKJRST
␈↓ ↓H␈↓ε           COMBOOL
␈↓ ↓H␈↓ε           COMPANDOR
␈↓ ↓H␈↓ε           COMPANDOR1
␈↓ ↓H␈↓ε           FLAT)
␈↓ ↓H␈↓εVALUE)

␈↓ ↓H␈↓ε(DEFPROP COMPL
␈↓ ↓H␈↓ε (LAMBDA(FILE)
␈↓ ↓H␈↓ε  (UWRITE)
␈↓ ↓H␈↓ε  (APPLY (QUOTE EREAD) FILE)
␈↓ ↓H␈↓ε  (SELECT-DISK-INPUT
␈↓ ↓H␈↓ε   (READ-UNTIL-EOF
␈↓ ↓H␈↓ε    WITH
␈↓ ↓H␈↓ε    Z
␈↓ ↓H␈↓ε    DO
␈↓ ↓H␈↓ε    (COND ((OR (EQ (CAR Z) (QUOTE DEFUN)) (AND (EQ (CAR Z) (QUOTE DEFPROP)) (EQ (CADDDR Z) (QUOTE EXPR))))
␈↓ ↓H␈↓ε           (PROG (PROG)
␈↓ ↓H␈↓ε                 (SETQ PROG
␈↓ ↓H␈↓ε                       (COND ((EQ (CAR Z) (QUOTE DEFUN)) (COMP (CADR Z) (CADDR Z) (CADDDR Z)))
␈↓ ↓H␈↓ε                             (T (COMP (CADR Z) (CADR (CADDR Z)) (CADDR (CADDR Z))))))
␈↓ ↓H␈↓ε                 (UNSELECT-TTY (SELECT-DISK-OUTPUT (MAPC (FUNCTION PRINT) PROG)))
␈↓ ↓H␈↓ε                 (PRINT (LIST (CADR Z) (LENGTH PROG)))))
␈↓ ↓H␈↓ε          (T (UNSELECT-TTY (SELECT-DISK-OUTPUT (PRINT Z))))))
␈↓ ↓H␈↓ε   (APPLY (QUOTE UFILE) (LIST (CAR FILE) (QUOTE LAP)))
␈↓ ↓H␈↓ε   (QUOTE ENDCOMP)))
␈↓ ↓H␈↓εFEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMP
␈↓ ↓H␈↓ε (LAMBDA(FN VARS EXP)
␈↓ ↓H␈↓ε  ((LAMBDA(VPR N)
␈↓ ↓H␈↓ε    (FLAT (LIST (LIST (LIST (QUOTE LAP) FN (QUOTE SUBR)))
␈↓ ↓H␈↓ε                (MKPUSH N 1)
␈↓ ↓H␈↓ε                (COMPEXP EXP (MINUS N) VPR)
␈↓ ↓H␈↓ε                (SUBSTACK N)
␈↓ ↓H␈↓ε                (QUOTE ((POPJ P) (LABEL NIL))))
␈↓ ↓H␈↓ε          NIL))
␈↓ ↓H␈↓ε   (PRUP VARS 1)
␈↓ ↓H␈↓ε   (LENGTH VARS)))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP SUBSTACK
␈↓ ↓H␈↓ii␈↓ ¬]APPENDIX IV␈↓ H


␈↓ ↓H␈↓ε (LAMBDA (N) (COND ((= N 0) NIL) (T (LIST (LIST (QUOTE SUB) (QUOTE P) (LIST (QUOTE %) 0 0 N N))))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP PRUP
␈↓ ↓H␈↓ε (LAMBDA (VARS N) (COND ((NULL VARS) NIL) (T (CONS (CONS (CAR VARS) N) (PRUP (CDR VARS) (ADD1 N))))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP MKPUSH
␈↓ ↓H␈↓ε (LAMBDA (N M) (COND ((LESSP N M) NIL) (T (CONS (LIST (QUOTE PUSH) (QUOTE P) M) (MKPUSH N (ADD1 M))))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMPEXP
␈↓ ↓H␈↓ε (LAMBDA(EXP M VPR)
␈↓ ↓H␈↓ε  (COND ((NULL EXP) (QUOTE ((MOVEI 1 0))))
␈↓ ↓H␈↓ε        ((OR (EQ EXP T) (NUMBERP EXP)) (LIST (LIST (QUOTE MOVEI) 1 (LIST (QUOTE QUOTE) EXP))))
␈↓ ↓H␈↓ε        ((ATOM EXP) (LIST (LIST (QUOTE MOVE) 1 (PLUS M (CDR (ASSOC EXP VPR))) (QUOTE P))))
␈↓ ↓H␈↓ε        ((EQ (CAR EXP) (QUOTE CAR))
␈↓ ↓H␈↓ε         (COND ((ATOM (CADR EXP)) 
␈↓ ↓H␈↓ε                (LIST (LIST (QUOTE HLRZ) 1 (QUOTE @)(PLUS M (CDR (ASSOC (CADR EXP) VPR))) (QUOTE P))))
␈↓ ↓H␈↓ε               (T (LIST (COMPEXP (CADR EXP) M VPR) (QUOTE ((HLRZ 1 @ 1)))))))
␈↓ ↓H␈↓ε        ((EQ (CAR EXP) (QUOTE CDR))
␈↓ ↓H␈↓ε         (COND ((ATOM (CADR EXP)) 
␈↓ ↓H␈↓ε                (LIST (LIST (QUOTE HRRZ) 1 (QUOTE @)(PLUS M (CDR (ASSOC (CADR EXP) VPR))) (QUOTE P))))
␈↓ ↓H␈↓ε               (T (LIST (COMPEXP (CADR EXP) M VPR) (QUOTE ((HRRZ 1 @ 1)))))))
␈↓ ↓H␈↓ε        ((OR (EQ (CAR EXP) (QUOTE AND))
␈↓ ↓H␈↓ε             (EQ (CAR EXP) (QUOTE OR))
␈↓ ↓H␈↓ε             (EQ (CAR EXP) (QUOTE NOT))
␈↓ ↓H␈↓ε             (EQ (CAR EXP) (QUOTE EQ)))
␈↓ ↓H␈↓ε         ((LAMBDA(L1 L2)
␈↓ ↓H␈↓ε           (LIST (COMBOOL EXP M L1 NIL VPR)
␈↓ ↓H␈↓ε                 (LIST (QUOTE (MOVEI 1 (QUOTE T)))
␈↓ ↓H␈↓ε                       (LIST (QUOTE JRST) 0 L2)
␈↓ ↓H␈↓ε                       (LIST (QUOTE LABEL) L1)
␈↓ ↓H␈↓ε                       (QUOTE (MOVEI 1 0))
␈↓ ↓H␈↓ε                       (LIST (QUOTE LABEL) L2))))
␈↓ ↓H␈↓ε          (GENSYM)
␈↓ ↓H␈↓ε          (GENSYM)))
␈↓ ↓H␈↓ε        ((EQ (CAR EXP) (QUOTE COND)) (COMCOND (CDR EXP) M (GENSYM) VPR))
␈↓ ↓H␈↓ε        ((EQ (CAR EXP) (QUOTE QUOTE)) (LIST (LIST (QUOTE MOVEI) 1 EXP)))
␈↓ ↓H␈↓ε        ((ATOM (CAR EXP))
␈↓ ↓H␈↓ε         (LIST (COMPLISA (CDR EXP) M VPR)
␈↓ ↓H␈↓ε               (LIST (LIST (QUOTE CALL) (LENGTH (CDR EXP)) (LIST (QUOTE QUOTE) (CAR EXP))))))
␈↓ ↓H␈↓ε        ((EQ (CAAR EXP) (QUOTE LAMBDA))
␈↓ ↓H␈↓ε         ((LAMBDA(N)
␈↓ ↓H␈↓ε           (LIST (STACKUP (CDR EXP) M VPR)
␈↓ ↓H␈↓ε                 (COMPEXP (CADDAR EXP) (DIFFERENCE M N) (APPEND (PRUP (CADAR EXP) (DIFFERENCE 1 M)) VPR))
␈↓ ↓H␈↓ε                 (SUBSTACK N)))
␈↓ ↓H␈↓ε          (LENGTH (CDR EXP))))
␈↓ ↓H␈↓ε        (T NIL)))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP STACKUP
␈↓ ↓H␈↓ε (LAMBDA(U M VPR)
␈↓ ↓H␈↓ε  (COND ((NULL U) NIL) (T (LIST (COMPEXP (CAR U) M VPR) (QUOTE ((PUSH P 1))) (STACKUP (CDR U) (SUB1 M) VPR)))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP CCCHAIN
␈↓ ↓H␈↓ε (LAMBDA(EXP)
␈↓ ↓H␈↓ε  (AND (OR (EQ (CAR EXP) (QUOTE CAR)) (EQ (CAR EXP) (QUOTE CDR))) (OR (ATOM (CADR EXP)) (CCCHAIN (CADR EXP)))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMPC
␈↓ ↓H␈↓ε (LAMBDA(EXP N2 M VPR)
␈↓ ↓H␈↓ε  (COND ((ATOM EXP) (ERROR (QUOTE COMPC)))
␈↓ ↓H␈↓ε        ((EQ (CAR EXP) (QUOTE CAR))
␈↓ ↓H␈↓␈↓ ¬]APPENDIX IV␈↓ -iii


␈↓ ↓H␈↓ε         (COND ((ATOM (CADR EXP))
␈↓ ↓H␈↓ε                (LIST (LIST (QUOTE HLRZ) N2 (QUOTE @)(PLUS M (CDR (ASSOC (CADR EXP) VPR))) (QUOTE P))))
␈↓ ↓H␈↓ε               (T (CONS (LIST (QUOTE HLRZ) N2 (QUOTE @) N2) (COMPC (CADR EXP) N2 M VPR)))))
␈↓ ↓H␈↓ε        ((ATOM (CADR EXP)) (LIST (LIST (QUOTE HRRZ) (QUOTE @) N2 (PLUS M (CDR (ASSOC (CADR EXP) VPR))) (QUOTE P))))
␈↓ ↓H␈↓ε        (T (CONS (LIST (QUOTE HRRZ) N2 (QUOTE @) N2) (COMPC (CADR EXP) N2 M VPR)))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMCOND
␈↓ ↓H␈↓ε (LAMBDA(U M L VPR)
␈↓ ↓H␈↓ε  (COND ((NULL U) (LIST (LIST (QUOTE LABEL) L)))
␈↓ ↓H␈↓ε        ((AND (NOT (ATOM (CAAR U))) (EQ (CAAAR U) (QUOTE NULL)) (NULL (CADAR U)))
␈↓ ↓H␈↓ε         (LIST (COMPEXP (CADAAR U) M VPR) (LIST (LIST (QUOTE JUMPE) 1 L)) (COMCOND (CDR U) M L VPR)))
␈↓ ↓H␈↓ε        ((EQ (CAAR U) T) (LIST (COMPEXP (CADAR U) M VPR) (LIST (LIST (QUOTE LABEL) L))))
␈↓ ↓H␈↓ε        (T
␈↓ ↓H␈↓ε         ((LAMBDA(L1)
␈↓ ↓H␈↓ε           (LIST (COMBOOL (CAAR U) M L1 NIL VPR)
␈↓ ↓H␈↓ε                 (COMPEXP (CADAR U) M VPR)
␈↓ ↓H␈↓ε                 (LIST (LIST (QUOTE JRST) 0 L) (LIST (QUOTE LABEL) L1))
␈↓ ↓H␈↓ε                 (COMCOND (CDR U) M L VPR)))
␈↓ ↓H␈↓ε          (GENSYM)))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMPLISA
␈↓ ↓H␈↓ε (LAMBDA(U M VPR)
␈↓ ↓H␈↓ε  ((LAMBDA(Z)
␈↓ ↓H␈↓ε    (LIST (COMPLIS Z M 1 VPR)
␈↓ ↓H␈↓ε          (LOADAC Z (DIFFERENCE 1 (CCOUNT Z)) 1 (DIFFERENCE M (CCOUNT Z)) VPR)
␈↓ ↓H␈↓ε          (SUBSTACK (CCOUNT Z))))
␈↓ ↓H␈↓ε   (CLASSIFY U)))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP CCOUNT
␈↓ ↓H␈↓ε (LAMBDA (Z) (COND ((NULL Z) 0) ((= (CAAR Z) 4) (ADD1 (CCOUNT (CDR Z)))) (T (CCOUNT (CDR Z)))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP LOADAC
␈↓ ↓H␈↓ε (LAMBDA(Z M2 N2 M VPR)
␈↓ ↓H␈↓ε  (COND ((NULL Z) NIL)
␈↓ ↓H␈↓ε        ((= (CAAR Z) 1)
␈↓ ↓H␈↓ε         (CONS (LIST (QUOTE MOVE) N2 (PLUS M (CDR (ASSOC (CDAR Z) VPR))) (QUOTE P))
␈↓ ↓H␈↓ε               (LOADAC (CDR Z) M2 (ADD1 N2) M VPR)))
␈↓ ↓H␈↓ε        ((= (CAAR Z) 0)
␈↓ ↓H␈↓ε         (CONS (LIST (QUOTE MOVEI) N2 (LIST (QUOTE QUOTE) (CDAR Z))) (LOADAC (CDR Z) M2 (ADD1 N2) M VPR)))
␈↓ ↓H␈↓ε        ((= (CAAR Z) 2) (CONS (LIST (QUOTE MOVEI) N2 (CDAR Z)) (LOADAC (CDR Z) M2 (ADD1 N2) M VPR)))
␈↓ ↓H␈↓ε        ((= (CAAR Z) 3) (LIST (REVERSE (COMPC (CDAR Z) N2 M VPR)) (LOADAC (CDR Z) M2 (ADD1 N2) M VPR)))
␈↓ ↓H␈↓ε        ((= (CAAR Z) 5) (LOADAC (CDR Z) 1 (ADD1 N2) M VPR))
␈↓ ↓H␈↓ε        (T (CONS (LIST (QUOTE MOVE) N2 M2 (QUOTE P)) (LOADAC (CDR Z) (ADD1 M2) (ADD1 N2) M VPR)))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMPLIS
␈↓ ↓H␈↓ε (LAMBDA(Z M K VPR)
␈↓ ↓H␈↓ε  (COND ((NULL Z) NIL)
␈↓ ↓H␈↓ε        ((= (CAAR Z) 4)
␈↓ ↓H␈↓ε         (LIST (COMPEXP (CDAR Z) M VPR) (QUOTE ((PUSH P 1))) (COMPLIS (CDR Z) (SUB1 M) (ADD1 K) VPR)))
␈↓ ↓H␈↓ε        ((= (CAAR Z) 5) (LIST (COMPEXP (CDAR Z) M VPR) (COND ((= K 1) NIL) (T (LIST (LIST (QUOTE MOVE) K 1))))))
␈↓ ↓H␈↓ε        (T (COMPLIS (CDR Z) M (ADD1 K) VPR))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP CLASSIFY
␈↓ ↓H␈↓ε (LAMBDA (U) (CLASS2 (CLASS1 U NIL) NIL T))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP CLASS1
␈↓ ↓H␈↓ε (LAMBDA(U V)
␈↓ ↓H␈↓ε  (COND ((NULL U) V)
␈↓ ↓H␈↓iv␈↓ ¬]APPENDIX IV␈↓ H


␈↓ ↓H␈↓ε        ((ATOM (CAR U))
␈↓ ↓H␈↓ε         (COND ((OR (EQUAL (CAR U) NIL) (EQUAL (CAR U) T) (NUMBERP (CAR U)))
␈↓ ↓H␈↓ε                (CLASS1 (CDR U) (CONS (CONS 0 (CAR U)) V)))
␈↓ ↓H␈↓ε               (T (CLASS1 (CDR U) (CONS (CONS 1 (CAR U)) V)))))
␈↓ ↓H␈↓ε        ((EQUAL (CAAR U) (QUOTE QUOTE)) (CLASS1 (CDR U) (CONS (CONS 2 (CAR U)) V)))
␈↓ ↓H␈↓ε        ((CCCHAIN (CAR U)) (CLASS1 (CDR U) (CONS (CONS 3 (CAR U)) V)))
␈↓ ↓H␈↓ε        (T (CLASS1 (CDR U) (CONS (CONS 4 (CAR U)) V)))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP CLASS2
␈↓ ↓H␈↓ε (LAMBDA(U V FLG)
␈↓ ↓H␈↓ε  (COND ((NULL U) V)
␈↓ ↓H␈↓ε        ((AND FLG (= (CAAR U) 4)) (CLASS2 (CDR U) (CONS (CONS 5 (CDAR U)) V) NIL))
␈↓ ↓H␈↓ε        (T (CLASS2 (CDR U) (CONS (CAR U) V) FLG))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP MKJRST
␈↓ ↓H␈↓ε (LAMBDA (L) (LIST (LIST (QUOTE JRST) 0 L)))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMBOOL
␈↓ ↓H␈↓ε (LAMBDA(P M L FLG VPR)
␈↓ ↓H␈↓ε  (COND ((EQ P T) (COND (FLG (MKJRST L)) (T NIL)))
␈↓ ↓H␈↓ε        ((ATOM P) (LIST (COMPEXP P M VPR) (LIST (LIST (COND (FLG (QUOTE JUMPN)) (T (QUOTE JUMPE))) 1 L))))
␈↓ ↓H␈↓ε        ((EQ (CAR P) (QUOTE EQ))
␈↓ ↓H␈↓ε         (LIST (COMPLISA (CDR P) M VPR) (COND (FLG (QUOTE ((CAMN 1 2)))) (T (QUOTE ((CAME 1 2))))) (MKJRST L)))
␈↓ ↓H␈↓ε        ((EQ (CAR P) (QUOTE AND))
␈↓ ↓H␈↓ε         (COND ((NOT FLG) (COMPANDOR (CDR P) M L NIL VPR))
␈↓ ↓H␈↓ε               (T
␈↓ ↓H␈↓ε                ((LAMBDA (L1) (LIST (COMPANDOR1 (CDR P) M L1 L NIL VPR) (LIST (LIST (QUOTE LABEL) L1))))
␈↓ ↓H␈↓ε                 (GENSYM)))))
␈↓ ↓H␈↓ε        ((EQ (CAR P) (QUOTE OR))
␈↓ ↓H␈↓ε         (COND (FLG (COMPANDOR (CDR P) M L T VPR))
␈↓ ↓H␈↓ε               (T
␈↓ ↓H␈↓ε                ((LAMBDA (L1) (LIST (COMPANDOR1 (CDR P) M L1 L T VPR) (LIST (LIST (QUOTE LABEL) L1))))
␈↓ ↓H␈↓ε                 (GENSYM)))))
␈↓ ↓H␈↓ε        ((EQ (CAR P) (QUOTE NOT)) (COMBOOL (CADR P) M L (NOT FLG) VPR))
␈↓ ↓H␈↓ε        ((EQ (CAR P) (QUOTE NULL))
␈↓ ↓H␈↓ε         (LIST (COMPEXP (CADR P) M VPR) (LIST (LIST (COND (FLG (QUOTE JUMPE)) (T (QUOTE JUMPN))) 1 L))))
␈↓ ↓H␈↓ε        (T (LIST (COMPEXP P M VPR) (LIST (LIST (COND (FLG (QUOTE JUMPN)) (T (QUOTE JUMPE))) 1 L))))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMPANDOR
␈↓ ↓H␈↓ε (LAMBDA(U M L FLG VPR)
␈↓ ↓H␈↓ε  (COND ((NULL U) NIL) (T (LIST (COMBOOL (CAR U) M L FLG VPR) (COMPANDOR (CDR U) M L FLG VPR)))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP COMPANDOR1
␈↓ ↓H␈↓ε (LAMBDA(U M L L2 FLG VPR)
␈↓ ↓H␈↓ε  (COND ((NULL U) (MKJRST L2))
␈↓ ↓H␈↓ε        ((NULL (CDR U)) (COMBOOL (CAR U) M L2 (NOT FLG) VPR))
␈↓ ↓H␈↓ε        (T (LIST (COMBOOL (CAR U) M L FLG VPR) (COMPANDOR1 (CDR U) M L L2 FLG VPR)))))
␈↓ ↓H␈↓εEXPR)

␈↓ ↓H␈↓ε(DEFPROP FLAT
␈↓ ↓H␈↓ε (LAMBDA(U S)
␈↓ ↓H␈↓ε  (COND ((NULL U) S)
␈↓ ↓H␈↓ε        ((NULL (CAR U)) (FLAT (CDR U) S))
␈↓ ↓H␈↓ε        ((EQ (CAR U) (QUOTE LABEL)) (CONS (CADR U) S))
␈↓ ↓H␈↓ε        ((ATOM (CAR U)) (CONS U S))
␈↓ ↓H␈↓ε        (T (FLAT (CAR U) (FLAT (CDR U) S)))))
␈↓ ↓H␈↓εEXPR)